0

我目前正在从事 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
4

0 回答 0