Question

Write an LC3 program that would implement if (x == 0) then y = y + 1; else y = y - 1;. Assume than variables x and y are...

Write an LC3 program that would implement if (x == 0) then y = y + 1; else y = y - 1;. Assume than variables x and y are at locations with labels x and y, respectively.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

     LD R0, x       ;load x

     BRnp ELSE       ; if x is zero then it will enter in clause else branch to ELSE
     LD R1, y       ; load y for add 1 in y
     ADD R1, R1, #1
     LD R1, y       ; restore R1 in y
     BR END_ELSE
ELSE
     LD R2, y       ; load y in R2
     LD R3, #1       ; load 1 in R3
     NOT R3, R3       ; taking compliment for subtraction
     ADD R3, R3, 1
     ADD R2, R2, R3   ; (y=y-1)
     LD R2, y       ; restore R2 in y

// if you got your solution then please give like to question

Add a comment
Know the answer?
Add Answer to:
Write an LC3 program that would implement if (x == 0) then y = y + 1; else y = y - 1;. Assume than variables x and y are...
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
ADVERTISEMENT