LC-3条件

时间:2016-03-06 22:34:28

标签: assembly lc3

我必须打印字符串“POSITIVE”,“NEGATIVE”或“ZERO”,具体取决于R0中的值。你如何表示LC-3中的多个条件?我以为我可以自己添加值来检查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"

1 个答案:

答案 0 :(得分:0)

.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