instructions I was following: .ORIG x3000 LD R3, negative_thirty ; Load the negative value x-30 into R3 TRAP x23 ; Read in first number from console ADD R0, R0, R3 ; Subtract
So I'm coding an assembly code I did wrong because it can't run in the lc-3 simulator I need help fixing my mistake here my code and the instructions I was following:
.ORIG x3000 LD R3, negative_thirty ; Load the negative value x-30 into R3
TRAP x23 ; Read in first number from console
ADD R0, R0, R3 ; Subtract x30 from the first number
STR R0, result1 ; Store the result in memory
LD R0, newline ; Load the newline character
TRAP x21 ; Output the newline character
TRAP x23 ; Read in second number from console
ADD R0, R0, R3 ; Subtract x30 from the second number
STR R0, result2 ; Store the result in memory
LD R0, newline ; Load the newline character
TRAP x21 ; Output the newline character
LD R1, num1 ; Load the first number into R1
LD R2, num2 ; Load the second number into R2
ADD R0, R1, R2 ; Add the two numbers
LD R3, negative_thirty ; Load the negative value x-30 into R3
NOT R3, R3 ; Negate the value in R3
ADD R0, R0, R3 ; Add x30 back to the result
TRAP x21 ; Output the sum
TRAP x25 ; Halt the program
result1 .FILL x0000 ; Memory location to store the first result
result2 .FILL x0000 ; Memory location to store the second result
num1 .FILL x0000 ; Memory location to store the first number
num2 .FILL x0000 ; Memory location to store the second number
negative_thirty .FILL xFFD0 ; Memory location to store the value x-30
newline .FILL x000A ; Memory location to store the newline character
.END
Trending now
This is a popular solution!
Step by step
Solved in 3 steps