Conditional Branches in the LC-3 Due: Report due beginning of lab the next week.
ID: 3607446 • Letter: C
Question
Conditional Branches in the LC-3 Due: Report due beginning of lab the next week. Be sure to email your code listings to the TA. Goal: To gain more experience programming the LC-3 computer in its native machine language, and to understand its conditional branching operations. For all of the following problems, have your program start at memory location x3000, and end with a HALT instruction. Be sure to use descriptive comments also. 1. Write a binary machine language program that compares the contents of R2 and R3, and puts the larger of the two into RI,If R2 and R3 are equal, put xFFFF in RI. Hint: Think about how a subtract operation might assist in comparing two values. Demonstrate it to your TA with the following values R2 R3 RI xFFOF xFOFF xFFOF #19 #19|xFFFF 2. Write a binary machine language program that multiplies the value stored in R2 by the value stored in R3 with the final result stored in R1. You can assume that the two operand values will not cause an overflow, but they can be either positive or negative. Remember: 3x4=-3x-4 = 4+4+4 -3×4= 3x-4 =-(3x4) Demonstrate it to your TA with the following values in this order. R2 R3 R1 3 4 x000C (12) 3 4 xFFF4 (-12) 3 0 x0000 (0) 3 4 xFFF4 (-12) 3 4 x000C (12) 0 4 x0000 (0)Explanation / Answer
1.
CMP R2,R3
BGT GT ; R2 > R3
BR LE ; R2 <= R3
GT:
LD R1, R2
BR EXIT
LE:
CMP R1, R2
BE EQ ; R2 = R3
LD R1, R3 ; R3 > R2
BR EXIT
EQ:
LD R1, xFFFF
BR EXIT
EXIT:
HALT
2. Multiplication by repeatative addition.
LD R4, 2 ; counter to add perform addition R3 times
MULT:
ADD R2, R2
ADD R4, #1
CMP R4, R3 ; Check if addtion has been performed R3 times or not
BLT MULT ; If counter R4 < R3 then loop back and perform more addition
BR EXIT
EXIT:
LD R1, R2
HALT
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.