I have to print the string "POSITIVE", "NEGATIVE" or "ZERO" depending on the value in R0
. How do you represent multiple conditionals in LC-3? I was thinking that I could just add the value with itself to check if R0
is positive, negative, or zero, but I can't understand how to check all three cases.
printCC ADD R1,R0,R0
BRp printPOS
printPOS LEA R0, StringPOS
PUTS
RET
StringNEG .STRINGZ "NEGATIVE\n"
StringZERO .STRINGZ "ZERO\n"
StringPOS .STRINGZ "POSITIVE\n"
.orig x3000
ADD R0, R0, #0 ; ensure that branch is dependent
; on R0 (the last result)
BRp printPOS
BRn printNEG
LEA R0, StringZERO
BR DONE
printNEG LEA R0, StringNEG
BR DONE
printPOS LEA R0, StringPOS
DONE PUTS
HALT
StringNEG .STRINGZ "NEGATIVE\n"
StringZERO .STRINGZ "ZERO\n"
StringPOS .STRINGZ "POSITIVE\n"
.end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.