The tables below show the contents of a few memory locations and registers befor
ID: 3807727 • Letter: T
Question
The tables below show the contents of a few memory locations and registers before and after an LC-3 instruction at location x3001 is executed. Identify the instruction located at x3001 given the information below. Write its LC-3 16-bit binary form and comment what it does. Explain how you arrived at your answer.
Before
After
R0
x1532
x1532
R1
x0244
x0244
R2
x533C
x533C
R3
x2100
x2100
R4
x3520
x3520
R5
x2279
x2279
R6
xEFFF
xEFFF
R7
x34C0
x34C0
x3500
x53A3
x53A3
x3501
x1743
x1743
x3502
x0D12
X0244
x3503
x5671
x5671
x3504
xF099
xF099
x3505
x8271
x8271
x3506
xEC90
xEC90
x3507
xBB12
xBB12
x3508
x9813
x9813
Answer:
LC-3 instruction
comment
Explanation:
Before
After
R0
x1532
x1532
R1
x0244
x0244
R2
x533C
x533C
R3
x2100
x2100
R4
x3520
x3520
R5
x2279
x2279
R6
xEFFF
xEFFF
R7
x34C0
x34C0
x3500
x53A3
x53A3
x3501
x1743
x1743
x3502
x0D12
X0244
x3503
x5671
x5671
x3504
xF099
xF099
x3505
x8271
x8271
x3506
xEC90
xEC90
x3507
xBB12
xBB12
x3508
x9813
x9813
Explanation / Answer
If you analyze the whole table content, only the value at memory location x3502 is changed after execution. All the other values are as it is. So, this means there is something done at this memory location. The content of memory location x3502 after execution becomes x0244 which is the value stored in register R1.
This means that the instruction at x3001 is storing the content of R1 at x3502.
For storing from register to memory, there are 3 options: ST, STI and STR.
Here, we will use STR instruction to write x3001 in our instruction because using the ST instruction (value of PC) or using STI(we have less than 16-bits to specify address), I will use STR which follows base + signed offset addressing.
We need to specify x3502. This is not directly stored in any register but the nearest value is x3520 stored in R4 and if we subtract x3520 with x3502, we get 30 in decimal or 1E in HEX. And as we want to go backwards from 3520 to 3502, we need to subtract 30 from base address i.e. add (-30)10 in base and we get x3502.
1E in binary is 0001 1110. So, its negative value(2's complement) is: 1110 0010 if we represent it in 6-bits the first is sign bit which is 1. Then the next five bits will be 00010. So, 100010 is what we need to write as an offset that means -30 because this sign is extended before adding to the base and it generates 16-bit offset as 11111111111111111111111111100010 (-30) which is added to x3520 and the outcome is x3502.
So, the required instruction is:
STR src base offset6 is its format where src and base are the registers.
So, it becomes STR R1, R4, 100010
The binary of STR is 0111. Register R1 is written in 3-bits as 001 and register R4 is written as 100.
So, the complete instruction in 16-bit binary becomes:
0111 001 100 100010
Where 0111 = STR, 001 = R1, 100 = R4, (Offset)6-bits = 100010 and this instruction stores the value stored in R1 at the base + offset address in memory where base address is stored in R4 which is x3520 and offset is x-1E so the destination becomes x3502. So the content of R1 which is x0244 is stored at memory location x3502 after this instruction is executed at location x3001.
Please comment if there is any query. Thank you. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.