【问题标题】:LC-3 ConditionalsLC-3 条件句
【发布时间】:2016-03-06 22:34:27
【问题描述】:

我必须根据R0 中的值打印字符串“POSITIVE”、“NEGATIVE”或“ZERO”。你如何在 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"

【问题讨论】:

    标签: assembly lc3


    【解决方案1】:
    .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
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多