CAO Mod1 Part2 MachineInsrtuctns
CAO Mod1 Part2 MachineInsrtuctns
CAO Mod1 Part2 MachineInsrtuctns
CS 202
Module -1 Part -2
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31= 0 for positive numbers
b 31= 1 for negative numbers
(a) A signed integer
I/O transfers
Register Transfer Notation
Three-Address Instructions
(operation destn, src1, src2)
ADD R1, R2, R3 ; R1 ← R2 + R3
Two-Address Instructions
(operation destn, src)
ADD R1, R2 ; R1 ← R1 + R2
One-Address Instructions
( in arithmetic operations, accumulator is implicit)
ADD B ; AC ← AC + M[B]
LOAD A ; AC ← M[A]
PUSH X ; TOS ← M[X]
Zero-Address Instructions
(all operands are implied to be in a pushdown stack)
ADD ; TOS ← TOS + (TOS – 1) (stack grows up)
(This operation has effect of popping the two top numbers from
stack, adding the numbers, and pushing the sum into the
stack)
Instruction Formats
Eg: Evaluate (A+B)(C+D) store result in X
Three-Address
1. ADD R1, A, B ; R1 ← M[A] + M[B]
2. ADD R2, C, D ; R2 ← M[C] + M[D]
3. MUL X, R1, R2 ; M[X] ← R1 R2
Instruction Formats
Immediate mode
Register mode
Absolute/ Direct mode
Indirect mode
Index mode
Base with index
Base with index and offset
Relative mode
Auto - increment mode
Auto - decrement mode
Immediate Addressing
Example
MOV R1,
#5R1
5
Register Addressing
• Operand is held in register, whose name (address)
given in instructn in address field
• EA = Ri (register address)
• Limited number of registers
• Very small address field needed
– Shorter instructions
– Faster instruction fetch and execution
• No memory access
• Very limited address space
Eg : MOV R1, R2
ADD R1, R2
Register Addressing Diagram
Example
MOV R1, R2
R1
R2 = 3
R3 = 5
Direct /Absolute Addressing
29
Direct /Absolute Addressing
Example
MOV R1, A
A = 101
100
101 0 1 0 4
102
103
104 1 1 0 A
Indirect Addressing (1/2)
• Memory cell pointed to by address field contains the address of
(pointer to) the operand
• EA =[A]
–Look in A, find an address (content of A) and look in memory
at that address location for operand
– In C programming, E=*D, D is a Pointer Variable
–Can be compiled into commands
MOV R1, D
MOV E, (R1)
– using indirect addressing => MOV E, (D)
• Large address space
• 2n where n = word length
• May be nested, multilevel, cascaded, e.g. EA = (((A)))
• Multiple memory accesses ,Hence slower
Indirect Addressing Diagram
Example
MOV R1, (A)
A = 101
100
101 0 1 0 4
102
103
104 1 1 0 A
Register Indirect Addressing
• Operand is in register or memory cell pointed to by contents of
register Ri
• EA = [Ri]
• Large address space (2n)
• One fewer memory access than indirect addressing
Register Indirect Addressing Diagram
Example
MOV R1,
(R2)
R1
R2 = 3
R3 = 5
Indexed / Displacement Addressing
Indexing and Arrays
Index mode – the effective address of the operand is
generated by adding a constant value to the contents of a
register.
X( Ri ) ; EA = [ Ri ] + X
Ri Index register
X constant given either as an explicit number or as a
symbolic name representing a numerical value.
Effective address= start address + displacement
(Index register holds address of a new location and value
of X defines an offset (displacement))
Good for accessing arrays
Indexed / Displacement Addressing
Indexed Address
EA = Index Register value + Relative Addr
Example
MOV R2, 3(R1)
3
100
R1 = 100
101
102
103 1 1 0 A
104
Indexing and Arrays…
Index mode facilitates access to an operand whose location is
defined relative to a reference point within the data structure in
which the operand appears.
Several variations:
X( Ri ) ; EA = [ Ri ] + X (Index)
EA is the sum of two values; one is given explicitly in the
instruction, and the other is stored in a register.
( Ri, Rj ) ; EA = [ Ri ] + [ Rj ] (Base with Index)
a A second register (base register) may be used to contain the
offset X. EA is the sum of the contents of registers Ri and Rj.
X( Ri, Rj ) ; EA = X + [ Ri ] + [ Rj ] (Base with Index and
offset)
EA is sum of constant X and contents of registers Ri and Rj .
It is useful in accessing multiple components inside each item
in a record, where the beginning of an item is specified by
(Ri, Rj) part of addressing mode (3D arrays).
Relative Addressing (PC-Relative)
0
1
PC= 2 2
Example
MOV R1, 100(PC) +
100
X = 100
101
102 1 1 0 A
103
104
Autoincrement mode
the effective address of the operand is the contents of a
register specified in the instruction.
After accessing the operand, the contents of this register are
automatically incremented to point to the next item in a list.
( Ri )+ EA = [ Ri ] ;
Increment Ri
The increment is 1 for byte-sized operands, 2 for 16-bit
operands, and 4 for 32-bit operands.
Example
ADD (R1)+, 3 ; M[R1]←M[R1]+3, R1 ←R1+1
Autodecrement mode
- (Ri) Decrement Ri ;
EA = [ Ri ];
Addressing Modes
The different ways in which the location of an operand is specified in an instruction
are referred to as addressing modes.
Instruction Execution and Straight-Line Sequencing
Assumptions:
- One memory operand
per instruction
- 32-bit word length
- Memory is byte
addressable
- Full memory address
can be directly specified
in a single-word instruction
Two-phase procedure:
- Instruction fetch
- Instruction execute
Branching
Branching
Condition Codes
Example: A: 11110000
A: 1 1 1 1 0 0 0 0 +(−B): 1 1 1 0 1 1 0 0
B: 0 0 0 1 0 1 0 0 11011100
C=1 Z=0
N=1
V=0