This program subtracts two numbers and stores the result in R3. Modify the following program in lc-3 to get the two numbers from the keyboard and print the result to the console. Write the complete functional program. .ORIG x3000 Loop LD R0, number1 ; load number1 into R0 LDR R1, number2 ; load number2 into R1 ST R2, SaveR2 ; save register R2 LD R5, goSUB ; load address of SUB into R4 JSRR R5 ; go to subroutine whose address in R5 STR R3, result ; store result LD R2, SaveR2 ; restore old value R2 HALT number1 .FILL #10 number2 .FILL # -8 goSUB .FILL SUB ; initialize goSUB to address of SUB SaveR2 .BLKW #1; reserve space SaveR2 and SaveR3 result .BLKW #1 SUB NOT R1, R1 ADD R2, R1, #1 ADD R3, R0, R2 RET .END
This
.ORIG x3000
Loop LD R0, number1 ; load number1 into R0
LDR R1, number2 ; load number2 into R1
ST R2, SaveR2 ; save register R2
LD R5, goSUB ; load address of SUB into R4
JSRR R5 ; go to subroutine whose address in R5
STR R3, result ; store result
LD R2, SaveR2 ; restore old value R2
HALT
number1 .FILL #10
number2 .FILL # -8
goSUB .FILL SUB ; initialize goSUB to address of SUB
SaveR2 .BLKW #1; reserve space SaveR2 and SaveR3
result .BLKW #1
SUB NOT R1, R1
ADD R2, R1, #1
ADD R3, R0, R2
RET
.END

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









