Beruflich Dokumente
Kultur Dokumente
Topics covered:
Instruction Set Architecture
Instruction execution and sequencing
2
Instruction execution and sequencing (contd..)
3
Instruction execution and sequencing (contd..)
Execution steps:
0 Move A, R0
Step I:
4 Add B, R0 -PC holds address 0.
8 Move R0, C -Fetches instruction at address 0.
-Fetches operand A.
-Executes the instruction.
-Increments PC to 4.
Step II:
-PC holds address 4.
A -Fetches instruction at address 4.
-Fetches operand B.
-Executes the instruction.
-Increments PC to 8.
B Step III:
-PC holds address 8.
-Fetches instruction at address 8.
-Executes the instruction.
C -Stores the result in location C.
Instructions are executed one at a time in order of increasing addresses.
“Straight line sequencing”
4
Instruction execution and sequencing (contd..)
Consider the following task:
Add 10 numbers.
Number of numbers to be added (in this case 10) is stored in
location N.
Numbers are located in the memory at NUM1, .... NUM10
Store the result in SUM.
Move NUM1, R0 (Move the contents of location NUM1 to register R0)
Add NUM2, R0 (Add the contents of location NUM2 to register R0)
Add NUM3, R0 (Add the contents of location NUM3 to register R0)
Add NUM4, R0 (Add the contents of location NUM4 to register R0)
Add NUM5, R0 (Add the contents of location NUM5 to register R0)
Add NUM6, R0 (Add the contents of location NUM6 to register R0)
Add NUM7, R0
Add NUM8, R0
Add NUM9, R0
Add NUM10, R0
Move R0, SUM (Move the contents of register R0 to location SUM)
5
Instruction sequencing and execution (contd..)
6
Instruction execution and sequencing (contd..)
Decrement R1:
Initially holds the number of numbers that is to be added
(Move N, R1).
Decrements the count each time a new number is added
(Decrement R1).
Keeps a count of the number of the numbers added so far.
Branch>0 LOOP:
Checks if the count in register R1 is 0 (Branch > 0)
If it is 0, then store the sum in register R0 at memory location
SUM (Move R0, SUM).
If not, then get the next number, and repeat (go to LOOP). Go
to is specified implicitly.
Note that the instruction (Branch > 0 LOOP) has no explicit
reference to register R1.
7
Instructions execution and sequencing (contd..)
8
Instruction execution and sequencing (contd..)
9
Instruction sequencing and execution (contd..)
Move N, R1
Move #NUM1, R2 (Initialize R2 with address of NUM1)
Clear R0
LOOP Add (R2), R0 (Indirect addressing)
Add #4, R2 (Increment R2 to point to the next number)
Decrement R1
Branch>0 LOOP
Move R3, SUM
10
Instruction execution and sequencing (contd..)
Move N, R1
Move #NUM1, R2 (Initialize R2 with address of NUM1)
Clear R0
LOOP Add (R2)+, R0 (Autoincrement)
Decrement R1
Branch>0 LOOP
Move R3, SUM
11
Stacks
12
Stacks (contd..)
13
Stacks (contd..)
14
Subroutines
15
Subroutines (contd..)
Return instruction:
Branch to the address contained in the link register.
16
Subroutines (contd..)
Memory Memory
location Calling program location Subroutine SUB •Calling program calls a subroutine,
whose first instruction is at address
100.
•The Call instruction is at address
200 Call SUB 1000 first instruction
204 next instruction 200.
•While the Call instruction is being
Return executed, the PC points to the next
instruction at address 204.
•Call instructions stores address 204
in the Link register, and loads 1000
1000
into the PC.
•Return instruction loads back the
PC 204 address 204 from the link register
into the PC.
Link 204
Call Return
17
Subroutines and stack
18
Assembly language
19
Assembly language (contd..)
20
Assembly language (contd..)
21
Assembly language (contd..)
100 Move N,R1
•What is the numeric value assigned to SUM?
104 Move #NUM1,R2
•What is the address of the data NUM1 through
108 Clear R0
LOOP 112 Add (R2),R0
NUM100?
116 Add #4,R2
•What is the address of the memory location
120 Decrement R1 represented by the label LOOP?
124 Branch>0 LOOP •How to place a data value into a memory
128 Move R0,SUM location?
132
SUM 200
N 204 100
NUM1 208
NUM2 212
NUM100 604
22
Assembly language (contd..)
EQU:
Memory Addressing •Value of SUM is 200.
address or data
ORIGIN:
label Operation information
•Place the datablock at 204.
DATAWORD:
Assembler directives SUM EQU 200 •Place the value 100 at 204
ORIGIN 204 •Assign it label N.
N DATAWORD 100 •N EQU 100
NUM1 RESERVE 400 RESERVE:
ORIGIN 100 •Memory block of 400 words
Statements that START MOVE N,R1 is to be reserved for data.
generate MOVE #NUM1,R2 •Associate NUM1 with address
machine CLR R0
208
instructions LOOP ADD (R2),R0
ADD #4,R2 ORIGIN:
DEC R1 •Instructions of the object
BGTZ LOOP program to be loaded in memory
MOVE R0,SUM starting at 100.
Assembler directives RETURN RETURN:
END START •Terminate program execution.
END:
•End of the program source text
23
Assembly language (contd..)
Assembly language instructions have a generic form:
Label Operation Operand(s) Comment
Four fields are separated by a delimiter, typically one or more
blank characters.
Label is optionally associated with a memory address:
May indicate the address of an instruction to be executed.
May indicate the address of a data item.
How does the assembler determine the values that represent
names?
Value of a name may be specified by EQU directive.
• SUM EQU 100
A name may be defined in the Label field of another instruction,
value represented by the name is determined by the location of that
instruction in the object program.
• E.g., BGTZ LOOP, the value of LOOP is the address of the instruction
ADD (R2) R0
24
Assembly language (contd..)
25
Encoding of machine instructions
26
Encoding of machine instructions (contd..)
One-word instruction format.
8 7 7 10
Opcode : 8 bits.
Source operand : 4 bits to specify a register
3 bits to specify the addressing mode.
Destination operand : 4 bits to specify a register.
3 bits to specify the addressing mode.
Other information : 10 bits to specify other information
such as index value.
27
Encoding of machine instructions (contd..)
What if the source operand is a memory location specified
using the absolute addressing mode?
8 3 7 14
Opcode : 8 bits.
Source operand : 3 bits to specify the addressing mode.
Destination operand : 4 bits to specify a register.
3 bits to specify the addressing mode.
28
Encoding of machine instructions (contd..)
29
Encoding of machine instructions (contd..)
Insist that all instructions must fit into a single 32 bit word:
Instruction cannot specify a memory location or an immediate
operand.
ADD R1, R2 can be specified.
ADD LOC, R2 cannot be specified.
Use indirect addressing mode: ADD (R3), R2
R3 serves as a pointer to memory location LOC.
How to load address of LOC into R3?
Relative addressing mode.
30
Encoding of machine instructions (contd..)
Three-operand instruction
31