Question

| 25 pts 25 pts) 2. 2. Write an LC3 program that compares two numbers x and y and puts the larger number in RI. Assume initia
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the simple program which will compare x and y, and will store 1 if x>y and -1 if x<y

           LD R1, x    ;load x into R1
           LD R2, y    ;load y into R2

           AND R6,R6,#0      ;initialize R0 with 0

           NOT R3, R2        ;R3 = -R2  (we negate NUMBER2)

           ADD R4, R3, R1    ;R4 = R1 - R2

           BRz Equals        ;we jump to Equals if x = y (we can just jump directly to END)
           BRn GreaterR2     ;we jump to GreaterR2 if x < y
           BRp GreaterR1     ;we jump to GreaterR2 if x > y

Equals     BRnzp End         ;nothing to do, because R0=0 (THIS IS NOT NECCESARY)

GreaterR2  ADD R0, R0, #-1   ;R0 = -1
           BRnzp End

GreaterR1  ADD R0, R0, #1    ;R0 = 1
           BRnzp End

Done       HALT               ;THE END


x .FILL #2              ;/ Declaration of numbers.
y .FILL #6              ;\

So above is the way in which we will compare the values x and y using LC3.

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Thanks

Add a comment
Know the answer?
Add Answer to:
| 25 pts 25 pts) 2. 2. Write an LC3 program that compares two numbers x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT