Data Movement Instructions: Topics To Discuss
Data Movement Instructions: Topics To Discuss
Topics to discuss…
1
Computer Programming TA C162
4 bits for opcode, 3 for src/dest register, 3 bits for base register
Remaining 6 bits are used as a signed offset.
2
Computer Programming TA C162
LDR (Base+Offset)
3
Computer Programming TA C162
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1
Opcode Destination Base Signed Offset (6 bits)
LDR R6
Register Register R5 x2F
4
Computer Programming TA C162
STR (Base+Offset)
5
Computer Programming TA C162
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1
Opcode Source Base Signed Offset (6 bits)
STR R6 Register R5 x2F
Register
6
Computer Programming TA C162
Solution #2
• Read address from memory location, then load/store to
that address.
7
Computer Programming TA C162
LDI (Indirect)
8
Computer Programming TA C162
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1
Destination
Opcode LDI R6 PC Offset (9 bits) x1AF
Register
Assume this LDI instruction is in the location x2345. While this instruction
is in execution, PC will have x2346.
Sign Extended offset is xFFAF
The address of operand’s address is xFFAF + x 2346
Assume the contents of the memory location (xFFAF + x 2346) xABC6
So the address of the operand becomes xABC6
So finally contents of memory location xABC6 will be loaded in R6
9
Computer Programming TA C162
STI (Indirect)
10
Computer Programming TA C162
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1
Destination
Opcode STI R6 PC Offset (9 bits) x1AF
Register
Assume this STI instruction is in the location x2345. While this instruction
is in execution, PC will have x2346.
Sign Extended offset is xFFAF
The address of operand’s address is xFFAF + x 2346
Assume the contents of the memory location (xFFAF + x 2346) xABC6
So the address of the operand becomes xABC6
So finally contents of R6 will be STORED in memory location xABC6
11
Computer Programming TA C162
Why Immediate?
No memory access required for operand loading.
12
Computer Programming TA C162
LEA
13
Computer Programming TA C162
Excercise
Address Instruction Comments
LEA
x30F6 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 R1 ← PC – 3 = x30F4
ADD
x30F7 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 R2 ← R1 + 14 = x3102
ST M[PC - 5] ← R2
x30F8 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 M[x30F4] ← x3102
AND
x30F9 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2 ← 0
ADD
x30FA 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 R2 ← R2 + 5 = 5
STR
M[R1+14] ← R2
x30FB 0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 0 M[x3102] ← 5
LDI R3 ← M[M[x30F4]]
x30FC 1 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1 R3 ← M[x3102]
R3 ← 5
opcode
14