简体   繁体   English

LC-3有条件的

[英]LC-3 Conditionals

I have to print the string "POSITIVE", "NEGATIVE" or "ZERO" depending on the value in R0 . 我必须根据R0的值打印字符串“ POSITIVE”,“ NEGATIVE”或“ ZERO”。 How do you represent multiple conditionals in LC-3? 您如何在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. 我当时想我可以将其自身加上值以检查R0是正,负还是零,但是我不知道如何检查所有这三种情况。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM