Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Chapter 2 Data Manipulation Dr. Farzana Rahman Assistant Professor Department of Computer Science James Madison University 1 Some sldes are adapted from.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
INSTRUCTION SET ARCHITECTURES
Princess Sumaya Univ. Computer Engineering Dept. Chapter 2: IT Students.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
Instruction Set Architecture
The Little man computer
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
EET 2261 Unit 2 HCS12 Architecture
Implementation of a Stored Program Computer
1 Homework Reading –PAL, pp Machine Projects –MP2 due at start of Class 12 Labs –Continue labs with your assigned section.
Assembly & Machine Languages
RISC and CISC. Dec. 2008/Dec. and RISC versus CISC The world of microprocessors and CPUs can be divided into two parts:
Parul Polytechnic Institute Subject Code : Name Of Subject : Microprocessor and assembly language programming Name of Unit : Introduction to Microprossor.
Instruction Set Design by Kip R. Irvine (c) Kip Irvine, All rights reserved. You may modify and copy this slide show for your personal use,
How Computers Work Dr. John P. Abraham Professor UTPA.
The CPU The Central Presentation Unit Main Memory and Addresses Address bus and Address Space Data Bus Control Bus The Instructions set Mnemonics Opcodes.
1 Machine Language Alex Ostrovsky. 2 Introduction Hierarchy of computer languages: 1. Application-Specific Language (Matlab compiler) 2. High-Level Programming.
Explain giving examples as appropriate, the essential features of an instruction set of a CPU. Each instruction must contain 4 basic components: Operation.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
GCSE Computing#BristolMet Session Objectives#11 MUST identify what program instructions consist of SHOULD describe how instructions are coded as bit patterns.
What have mr aldred’s dirty clothes got to do with the cpu
Important Concepts  Parts of the CPU  Arithmetic/Logic Unit  Control Unit  Registers  Program Counter  Instruction Register  Fetch/Decode/Execute.
Computer Architecture and Organization
The 8051 Microcontroller and Embedded Systems
Computer Systems - Processor. Objectives To investigate and understand the structure and role of the processor.
Differences in ISA Instruction length
Represents different voltage levels High: 5 Volts Low: 0 Volts At this raw level a digital computer is instructed to carry out instructions.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Group # 3 Jorge Chavez Henry Diaz Janty Ghazi German Montenegro.
JUMP, LOOP, AND CALL INSTRUCTIONS
Ass. Prof. Dr Masri Ayob TK 2123 Lecture 14: Instruction Set Architecture Level (Level 2)
Representation of Data Binary Representation of Instructions teachwithict.weebly.com.
Lec 4-2 Five operations of the machine cycle Fetch- fetch the next program instruction from memory. (PC+1); instruction to IR Decode- decode the instruction.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
Instruction Set Architectures Continued. Expanding Opcodes & Instructions.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
The Little man computer
GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language.
Immediate Addressing Mode
Assembly Language (CSW 353)
Assembly Language Programming of 8085
Chapter 11 Instruction Sets
A Closer Look at Instruction Set Architectures
Stored program concept
Homework Reading Labs PAL, pp
Architecture Review Instruction Set Architecture
Processor Instructions set. Learning Objectives
A Closer Look at Instruction Set Architectures
Assembly Language Programming Part 2
A Closer Look at Instruction Set Architectures: Expanding Opcodes
CS 11 C track: lecture 8 Last week: hash tables, C preprocessor
THE sic mACHINE CSCI/CMPE 3334 David Egle.
Introduction to Assembly Language
Computer Organization and ASSEMBLY LANGUAGE
Fundamentals of Computer Organisation & Architecture
Homework Reading Machine Projects Labs PAL, pp
Classification of instructions
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Introduction to Microprocessor Programming
CPU Structure CPU must:
CS 111 – Sept. 16 Machine language examples Instruction execution
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Computer Systems – Machine & Assembly code

Objectives Machine Code Assembly Language Op-code Operand Instruction Set

Machine code Machine code - simple instructions that are executed directly by the CPU As we should hopefully already know, computers can only understand binary, 1s and 0s. We are now going to look at the simplest instructions that we can give a computer. This is called machine code Machine code allows computers to perform the most basic, but essential tasks. For this section we are going to use the Accumulator (you met this register earlier) to store the intermediate results of all our calculations. Amongst others, the following instructions are important for all processors: LDA - Loads the contents of the memory address or integer into the accumulator ADD - Adds the contents of the memory address or integer to the accumulator STO - Stores the contents of the accumulator into the addressed location

Assembly code Assembly code is the easy to read interpretation of machine code, there is a one to one matching, one line of assembly equals one line of machine code: Machine codeAssembly code Store 53 Let's take a look at a quick coding example using assembly code. LDA #23 ;loads the number 23 into the accumulator ADD #42 ;adds the number 42 to the contents of the accumulator = 65 STO 34 ;save the accumulator result to the memory address 34

Instruction Set Instruction set - the range of instructions that a CPU can execute There are many different instructions that we can use in machine code, you have already met three (LDA, ADD, STO), but some processors will be capable of understanding many more. The selection of instructions that a machine can understand is called the instruction set. Below are a list of some other instructions that might be used: ADD ;add one number to another number SUB ;subtract one number to another number INC ;increment a number by 1 DEC ;decrement a number by 1 MUL ;multiply numbers together OR ;boolean algebra function AND ;boolean algebra function NOT ;boolean algebra function XOR ;boolean algebra function JNZ ;jump to another section of code if a number is not zero (used for loops and ifs) JZ ;jump to another section of code if a number is zero (used for loops and ifs) JMP ;jump to another section of code (used for loops and ifs) ADD ;add one number to another number SUB ;subtract one number to another number INC ;increment a number by 1 DEC ;decrement a number by 1 MUL ;multiply numbers together OR ;boolean algebra function AND ;boolean algebra function NOT ;boolean algebra function XOR ;boolean algebra function JNZ ;jump to another section of code if a number is not zero (used for loops and ifs) JZ ;jump to another section of code if a number is zero (used for loops and ifs) JMP ;jump to another section of code (used for loops and ifs)

Instruction Set Let us look at a more complex example of assembly code instructions: LDA #12 ;loads the number 12 into the accumulator MUL #2 ;multiplies the accumulator by 2 = 24 SUB #6 ;take 6 away from the accumulator = 18 JNZ 6 ;if the accumulator <> 0 then goto line 6 SUB #5 ;take 5 away from the accumulator (this line isn't executed!) STO 34 ;saves the accumulator result (18) to the memory address 34

Machine Instruction You'll notice that in general instructions have two main parts: opcode - instruction name operand - data or address You'll notice that in general instructions have two main parts: opcode - instruction name operand - data or address

Machine Instruction Depending on the word size, there will be different numbers of bits available for the opcode and for the operand. There are two different philosophies at play, with some processors choosing to have lots of different instructions and a smaller operand (Intel, AMD) and others choosing to have less instructions and more space for the operand (ARM). CISC - Complex Instruction Set Computer - more instructions allowing for complex tasks to be executed, but range and precision of the operand is reduced. Some instruction may be of variable length, for example taking extra words (or bytes) to address full memory addresses, load full data values or just expand the available instructions. RISC - Reduced Instruction Set Computer - less instructions allowing for larger and higher precision operands.

Machine Instruction Addressing modes You might notice that some instructions use a # and others don't, # = number [no hash] = address # = number [no hash] = address LOAD #10 ADD #12 STORE 12 This code loads the number 10 into the accumulator, then adds the number 12, it then stores the result 22 into memory location 12

Machine code and instruction sets There is no set binary bit pattern for different opcodes in an instruction set. Different processors will use different patterns, but sometimes it might be the case that you are given certain bit patterns that represent different opcodes. You will then be asked to write machine code instructions using them. Below is an example of bit patterns that might represent certain instructions. Machine code Instruction Addressing mode Example 0000STOREAddressSTO LOADNumberLDA # LOADAddressLDA ADDNumberADD # ADDAddressADD HALTNoneHALT

Machine code and instruction sets Using the table on the last slide, provide machine code to do the following: LOAD 12 ADD #6 Answer Answer

Machine code and instruction sets Using the table on the last slide, provide assembly code for the following machine code: Answer LOAD 7 ADD 9 STORE 29 Answer LOAD 7 ADD 9 STORE 29 Explain what the above code does:

Machine code in Hexadecimal People who work with machine code prefer to display in Hexadecimal, this is because it takes less space than binary. Errors are less likely to occur when dealing with smaller data sets. Machine code Instruction Addressing mode HexadecimalExample 0000STOREAddress0STO LOADNumber1LDA # LOADAddress2LDA ADDNumber4ADD # ADDAddress8ADD HALTNoneFHALT

Machine code in Hexadecimal Convert the following machine code into hexadecimal: Answer 1 3B E F 0 Answer 1 3B E F 0

Key terms… Machine Code Assembly Language Op-code Operand Instruction Set