Presentation is loading. Please wait.

Presentation is loading. Please wait.

The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1.

Similar presentations


Presentation on theme: "The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1."— Presentation transcript:

1 The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1

2 Data Movement Instructions Recall that there are three types of instructions: – Operate instructions – Data movement instructions – Control instructions We consider the data movement instructions today

3 Data Movement Instructions Remember these types of instructions move data from registers to memory and back For now, we will not consider the movement of data from registers to input/output devices We consider only to/from memory to general purpose registers (GPRs)

4 Data Movement Instructions The process of move information from memory to a register is called a load The process of moving information from a register to memory is called a store In both cases, the source operand completely overwrites the destination operand

5 Data Movement Instructions The LC-3 has the following movement instructions: – LD – load PC relative – LDR – load base+offset – LDI – load indirect – LEA – load effective address – ST –store PC relative – STR – store base+offset – STI – store indirect

6 Data Movement Instructions The format of the load and store instructions is Bits [11:9] is first operand, a register – DR = destination register – SR = source register – Depends on whether load or store 1514131211109876543210 OpcodeDR or SRAddress Generation Bits

7 Data Movement Instructions Bits [8:0] contain the address generation bits This encodes the information for the 16 bit address of the second operand There are four ways to interpret this The opcode determines which way these bits are interpreted

8 PC-Relative Mode The opcodes LD (0010) and ST (0011) use PC-relative addressing mode Bits [8:0] refers to an offset of the PC address after it has been incremented The address is computed by sign extending [8:0] to 16 bits

9 LD (PC-Relative)

10 ST (PC-Relative)

11 PC-Relative Mode Note there are only 9 bits for the relative address offset This corresponds to -2 8 …2 8 -1 or -256…255 If the data is further away, then we must use some other instruction to get to the data such as LDR or LDI

12 PC-Relative Mode Consider the instruction This is LD R2,0x1AF Assume the instruction is at 0x4018 So 0x4019-0x51 = 0x3FC8 Then R2=MEM[0x3FC8] 1514131211109876543210 00100101101 01111

13 PC-Relative Mode Consider the instruction This is ST R6,0xDA Assume the instruction is at 0x4018 So 0x4019+0xDA = 0x40F3 Then MEM[0x40F3]=R6 1514131211109876543210 00111100110 11010

14 Indirect Mode LDI (1010) and STI (1011) specify indirect addressing mode for memory references The address is formed the same way as ST or LD by sign extending the address bits Then the value is added to the incremented value of the PC

15 Indirect Mode However, this is not the address of the operand This location contains the address of the operand! Hence, the name indirect You can think of the operand as a pointer to the real address

16 LDI (Indirect)

17 STI (Indirect)

18 Indirect Mode Consider the instruction The is LDI R3,0x1CC Assume the instruction is at 0x4A1B So 0x4A1B-0x34 = 0x49E8 Assume MEM[0x49E8]=0x2110 Then R3=MEM[0x2110] 1514131211109876543210 10100111110 01100

19 Indirect Mode


Download ppt "The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620 1."

Similar presentations


Ads by Google