背景:
我正在编写一个程序,要求用户输入“1”或“2”,该值的ASCII值加-49,并且取决于总和是0还是1,将打印一个字符串
冲突:
当我模拟我的代码时,我在控制台中得到了these weird y's。我尝试使用LD而不是LEA,但这并没有解决任何问题。我还注意到in my simulation在任何地方都没有Case 2 String(CAS2S),但我能够看到CAS1S。我不知道这意味着什么,但我怀疑它可能会导致我的问题。任何帮助将不胜感激。
谢谢!
CODE:
.ORIG x3000
; INPUT REQUEST: Store input value into R0
START TRAP x23
; FILL PROCESS: Put value -49 in address of FN. Load value in FN address (-49) into R4
LD R4, FN
; CASE CREATION: Add -49 (R4) to input value (R0)
ADD R3, R0, R4
; BRANCHES: If R3 = 0, execute Case 1 Instruction. If R3 > 0 (specifically if R3 = 1), execute Case 2 Instruction
BRz CAS1I
BRp CAS2I
; BRANCH CASES:
; CASE 1 INSTRUCTION: Load Case 1 String into R1. Print string in R1. Jump to START (input request).
CAS1I LEA R1, CAS1S
TRAP x22
BRnzp START
; CASE 2 INSTRUCTION: Load Case 2 String into R2. Print string in R2. Jump to START (input request).
CAS2I LEA R2, CAS2S
TRAP x22
BRnzp START
; STRING STORAGE: Store input patterns in Case 1 String and Case 2 String
CAS1S .STRINGZ "1100\n0110\n0011\n1001\n1100\n0110\n0011\n1001\n1100\n0110\n0011\n1001\n1100\n1001\n0011\n0110\n1100\n1001\n0011\n0110\n1100"
CAS2S .STRINGZ "1100\n1001\n0011\n0110\n1100"
FN .FILL #-49
.END
答案 0 :(得分:0)
迟到的响应,但这是因为您要打印的以null终止的字符串需要位于R0中。