Write a LC-3 assembly program to subtract two integers (between 0 and 9) provide
ID: 3825358 • Letter: W
Question
Write a LC-3 assembly program to subtract two integers (between 0 and 9) provided by the user. Prompt the user to input two integers, subtract one from the other, and display the difference. If the difference is negative, display the negative sign also.
Here’s the interaction for two different runs of the program:
Demo of a simple subtraction program:
Input an integer: 9
Input a second integer: 4
The difference is: 5
Demo of a simple subtraction program:
Input an integer: 5
Input a second integer: 8
The difference is: -3
Explanation / Answer
LD R0, X
LD R1, Y
NOT R1,R1
ADD R1,R1,1
ADD R0,R1
LD R1,Y
HALT
We have loaded the two user inputs into R0,R1
To subtract, we have first calculated two's compliment for R1
And with that value we have added it to R0, to get the subtracted value of R0 AND R1
Now we have restored it in R1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.