LC-3 If/Else 语句
我的 LC-3 程序有问题,无法从 if
/else
语句中显示字符串。我不知道我是否执行了错误的语句,或者是否显示了错误的字符串。目标是让它在用户输入 0
时显示 IF
,并在输入 时显示
.else
(停止程序) 1.
.ORIG x3000
START:
; clear registers
AND R0, R0, 0
AND R1, R0, 0
AND R2, R0, 0
AND R3, R0, 0
AND R4, R0, 0
; print greeting
LEA R0, GREETING
PUTS
; get user-input
; echo it back
GETC
PUTC
; store entered string
ST R0, USERINPUT
;FIRST IF STATEMENT
OUTPUT LD R2, USERINPUT
BRz ENDIF
LEA R3, GREETING
;ELSE
ENDIF
LD R2, USERINPUT
HALT
DONE
; stop the processor
HALT
GREETING: .STRINGZ "\nWelcome to the game.\nDo you want to play?\n0:Yes 1:No\n: "
GREETINGTWO: .STRINGZ "\nTest if statement: "
; variables
USERINPUT: .FILL 0
; end of code
.END
I have a problem with this LC-3 program, I can't get the string to display from the if
/else
statement. I don't know if I'm doing the statement wrong, or if I am displaying the string wrong. The goal is to have it display the IF
when the user enters 0
and the else
(halt the program) when they enter a 1
.
.ORIG x3000
START:
; clear registers
AND R0, R0, 0
AND R1, R0, 0
AND R2, R0, 0
AND R3, R0, 0
AND R4, R0, 0
; print greeting
LEA R0, GREETING
PUTS
; get user-input
; echo it back
GETC
PUTC
; store entered string
ST R0, USERINPUT
;FIRST IF STATEMENT
OUTPUT LD R2, USERINPUT
BRz ENDIF
LEA R3, GREETING
;ELSE
ENDIF
LD R2, USERINPUT
HALT
DONE
; stop the processor
HALT
GREETING: .STRINGZ "\nWelcome to the game.\nDo you want to play?\n0:Yes 1:No\n: "
GREETINGTWO: .STRINGZ "\nTest if statement: "
; variables
USERINPUT: .FILL 0
; end of code
.END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您显示的字符串不正确。
LEA 仅加载标签/内存偏移的有效地址,不会将其打印出来。如果要打印出字符串,则必须调用 TRAP x22(宏为 PUTS),如上面代码片段的第 14 行所示。
You're displaying the string incorrectly.
LEA only loads the effective address of a label/memory offset, it does not print it out. If you want to print out a string, you must call TRAP x22 (macroed to PUTS), as in the 14th line of your code snippet above.