[英]Storing in LC-3 issues
So I'm working on an assignment in LC-3 assembly language, and I'm having an issue. 因此,我正在使用LC-3汇编语言进行作业,但遇到了问题。 So the program is designed to use subroutine GETDEC to take in some input as a string from the keyboard and then interprets the input string to construct the integer value.
因此,该程序设计为使用子例程GETDEC从键盘接收一些输入作为字符串,然后解释输入字符串以构造整数值。 I think I'm close to getting the assignment done, but I seem to be stuck.
我想我快要完成任务了,但是我似乎陷入了困境。 We are meant to use a block of 8 words for the input buffer, and my issue is, that I can't seem to get my program to save the input string values in the block, which in turn prevents me from being able get out of the loop in my main method.
我们打算使用8个单词的块作为输入缓冲区,而我的问题是,我似乎无法让我的程序将输入字符串值保存在该块中,这又又使我无法下车我主要方法中的循环。
Here is the main method 这是主要方法
LEA R1, DATA
INPUT
LD R0, NEWLN
TRAP x21
LEA R0, PROMPT
TRAP x22
JSR GETDEC
STR R0, R1, #0
ADD R1, R1, #1
ADD R0, R0, #0
BRNP INPUT
LD R0, NEWLN
TRAP x21
LEA R1, DATA
OUTPUT
LDR R0, R1, #0
JSR PUTDEC
LD R0, NEWLN
TRAP x21
ADD R1, R1, #1
LDR R0, R1, #-1
BRNP OUTPUT
TRAP x25
NEWLN .FILL x000A
PROMPT .STRINGZ "Enter an integer, 0 to quit> "
DATA .BLKW 10
Here is my GETSTR subroutine, which gets the input as a string value 这是我的GETSTR子例程,该子例程将输入作为字符串值获取
GETSTR
ST R7, GET_7
ST R1, S1
ST R2, S2
ST R3, S3
ADD R1, R0, 0
TRAP x20 ;User input
TRAP x21 ;echoes input
STR R0,R1,0
AND R3,R3,0 ;clears R3
ADD R2, R0, 0 ;R2 <- R0
ADD R1, R1, #1 ;R3 <- R3+1
LD R3, PRZ ;R1 <- xF6 (-10)
ADD R2,R3,R2 ;R2 <- R1 + R2
BRnp -9 ;Branches back to User Input unless last flag is Zero
LD R1, S1
LD R2, S2
LD R3, S3
LD R7, GET_7
RET
GET_7 .BLKW 1
PRZ .FILL xFFF6
S1 .BLKW 1
S2 .BLKW 1
S3 .BLKW 1
And here's my GETDEC subroutine that takes the input string and interprets it into the corresponding integer value. 这是我的GETDEC子例程,该子例程接受输入字符串并将其解释为相应的整数值。
GETDEC ;Input a signed integer to R0
ST R7, GET7
ST R1, GET1
ST R2, GET2
LEA R0, JIMB ;Input a character string
JSR GETSTR
LD R2, JIMB
AND R0, R0, 0
HERE ADD R0, R0, R0 ; multiply by 10
ADD R1, R0, R0
ADD R1, R1, R1
ADD R0, R0, R1
ADD R0, R0, R2 ; R0 <- R0 + X
ADD R2, R2, 1 ; Increments R2
LD R3, WORK
ADD R3, R2, R3
BRnp HERE ;Loop if R2 = 0
LD R1, GET1
LD R2, GET2
LD R7, GET7
RET
GET1 .BLKW 1
GET7 .BLKW 1
GET2 .BLKW 1
JIMB .BLKW 8
WORK .FILL xFFD0
So to reiterate, the main method loops GETDEC until a 0 is entered at input, but something in my code is preventing me from breaking out of the loop when 0 is entered. 重申一下,main方法会循环GETDEC直到在输入中输入0为止,但是我的代码中的某些内容阻止了我在输入0时退出循环。 I think I might be using the wrong Load methods within the GETDEC subroutine, but I'm not sure, if anyone can help, it'd be greatly appreciated.
我想我可能在GETDEC子例程中使用了错误的Load方法,但是我不确定,如果有人可以提供帮助,将不胜感激。
I thing the storing is OK, and your problem is here (in GETDEC): 我认为存储可以,您的问题在这里(在GETDEC中):
JSR GETSTR
LD R2, JIMB <=
You load the data from the buffer here, not the buffer address. 您从此处的缓冲区而不是缓冲区地址中加载数据。 You probably need LEA.
您可能需要LEA。
Then here: 然后在这里:
ADD R0, R0, R2 ; R0 <- R0 + X
ADD R2, R2, 1 ; Increments R2
The first line treats R2 like data, and second line as pointer to the data. 第一行将R2视为数据,第二行视为指向数据的指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.