我目前正在使用LC-3汇编语言进行作业。该赋值实现了一个LC3汇编语言的程序,它接受用户输入字符串,将它们回送给用户,然后打包字符串。该程序已经完成,除了我们应该完成的2个子程序。我正在研究Get String子程序,我的代码陷入无限循环,我不知道为什么。如果不是太麻烦,有人可以查看我的代码,看看他们是否发现了问题?我认为这与我使用GETSTR子程序的分支有关,但我不确定。到目前为止,这是我的代码。
enter code here .ORIG x3000
LEA R0, PROMPT ;Prompt for input
TRAP x22
LD R0, STRING ;Input a character string
JSR GETSTR
LD R0, NEWLIN ;Start a new output line
TRAP x21
LD R0, STRING ;Display the input string
TRAP x22
JSR PAKSTR ;Pack the character string
LD R0, NEWLIN ;Start a new output line
TRAP x21
LD R0, STRING
TRAP x24 ;Display the packed string
LD R0, NEWLIN
TRAP x21
TRAP x25 ;Halt
;Data
NEWLIN .FILL x0A
STRING .FILL x3100
PROMPT .STRINGZ "Enter a character string, hit ENTER> "
;------------------------------------------------------------
GETSTR ;Input a character string from the keyboard to memory
;Each input character is echoed at the console
;End of input is signalled by NEWLN (Enter key) x0A
;The end of the string in memory is marked by x0000
;Parameters - R0 : address of the string
ST R7, GET_7
JUMP ADD R2, R0,0
ADD R2, R2, 1
TRAP x20
BRnp JUMP
TRAP x21
LD R7, GET_7
RET
GET_7 .BLKW 1
;---------------------------------------------------------------------
PAKSTR ;Create a packed string from a 0-terminated character string
;The packed string overwrites the original string in memory
;The format of a packed string is described in Table A.2, p543
;Parameters - R0 : address of the string
ST R7, PAK_7
BACK ADD R0, R0, R0
TRAP x24
BRnp BACK
LD R7, PAK_7
RET
PAK_7 .BLKW 1
.END