190 likes | 394 Views
The LC-3 – Chapter 5. COMP 2620. 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. Data Movement Instructions.
E N D
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP 2620
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
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)
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
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
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
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
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
PC-Relative Mode • Note there are only 9 bits for the relative address offset • This corresponds to -28…28-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
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]
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
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
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
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]