2. Construct the symbol table for the following LC-3 assembly language program. (10 points) 2) Assemble it into binary machine code line by line by hand. (30 points) 3) What does the program do? (10 points)
时间: 2024-01-12 07:05:28 浏览: 107
LC-3 assembly language program:
```
.ORIG x3000
AND R1, R1, #0
ADD R1, R1, #5
LOOP ST R1, NUM
ADD R1, R1, #-1
BRz EXIT
BRnzp LOOP
EXIT HALT
NUM .FILL x0000
.END
```
Symbol table:
| Symbol | Value |
|--------|-------|
| LOOP | x3003 |
| EXIT | x3008 |
| NUM | x3009 |
Binary machine code:
```
.ORIG x3000
0101000000000000 ; AND R1, R1, #0
0001000100000101 ; ADD R1, R1, #5
LOOP
0011000100001001 ; ST R1, NUM
0001000100000001 ; ADD R1, R1, #-1
0000000000000010 ; BRz EXIT
0000000000000011 ; BRnzp LOOP
EXIT
0000000000000101 ; HALT
NUM .FILL x0000
.END
```
Explanation of the program:
This program initializes R1 to 5, and then enters a loop that stores R1's value to the memory location labeled NUM, decrements R1, and checks if R1 is zero. If R1 is not zero, the program jumps back to the beginning of the loop. When R1 reaches zero, the program exits the loop and halts. Therefore, this program stores the numbers 5, 4, 3, 2, and 1 to memory location NUM.
阅读全文