Write an LC-3 program (machine code) that compares the two numbers located in x3600 and x3601 and puts the value 0 in R1 if the two numbers are equal, 1 if the first number is larger than the second number, and -1 if the first number is smaller than the second number.
1). ANSWER :
GIVENTHAT :
To write an LC-3 program
.ORIG x3500
LDI R1,x3600 ; Load R1 from memory content at x36000
LDI R2,x3601 ;Load R1 from memory content at x36001
AND R0,R0,#0 ;Initilize R0=0
NOT R3,R2 ;Negate Number 2
ADD R4,R3,R1 ;R4=R1-R3;
BRz eq ; if above step results zero,which indiacates both numbers are equal zero flag enabled
BRn le ;if above step results negative value negative flag enabled ,which indiacates first numbers ;smaller than second number
BRp gr ;if above step results negative value negative flag enabled ,which indiacates first numbers ;igger than second number
eq AND R0,R0,#0 ;make R0=0
BRnzp end
le ADD R0,R0,#-1 ;R0=-1
BRnzp end
gr ADD R0,R0,#1 ;R0=1
BRnzp end
HALT ;End
Get Answers For Free
Most questions answered within 1 hours.