最近,当我在大学开始学习MIPS时,我遇到了一个问题,我试图打印一个字符串,接受一个用户输入,然后打印另一个字符串并接受一个用户输入。两个用户输入都应该分别存储到寄存器a0和a1中。
每个字符串的名称是分红输入的promptD,除数输入的enterD (您可能猜这是一个无符号的除法计算器程序)。
在我的调试尝试中,我已经将问题缩小到下面发布的代码的一个小片段。
我认为我不正确地抵消了我的第一个.data寄存器到达我的第二个.data寄存器。当我尝试QTspim、xspim、PCspim和火星时,我注意到的问题是,所有这些都为.data中的第一个字符串提供了一个不同的初始注册地址。
例如:字符串“输入分红”将位于火星的reg地址0x10010000中,但将在PCspim中从0x10000000开始。以下“输入除数”的注册地址将位于火星上的0x10010011或PCspim中的0x10000010。
在目前的状态通过火星,下面的程序片段要求用户输入红利,它将存储的价值。在存储到a0之后,代码将立即失败,原因是第37行(这只是第三个syscall)运行时异常在0x00400024:地址超出了0x00000004。它根本没有提示“输入除数”。
要真正看到实际的问题,我认为在火星上运行这个项目会让它变得更清楚。这是一个抵消的问题吗?我是不是没看见就把登记簿弄坏了?我在这里找不到多少MIPS帮助来处理没有伪指令的问题。我意识到,有了它们,我可以直接加载一个地址(la)...but,我不能在这里使用它们。
谢谢
.globl main
.data #for the data
promptD: .asciiz "Enter Dividend \n"
enterD: .asciiz "Enter Divisor \n"
# result: .asciiz "Result = "
.text #for the instructions
main:
#for Dividend
addi $v0, $0, 4 #store string instr to v0
lui $a0, 0x1001 #address of promptD
syscall #display promptD
addi $v0, $0, 5 #store input instr to v0
syscall # Get dividend
add $a0, $0, $v0 # Dividend to $a0
#for Divisor
addi $v0, $0, 4 #store string instr to v0
lui $a1, 0x1001 #Where I think the problem is...
#Address of first string followed by add offset?
addi $a1, $a1, 33 #Maybe incorrect offset?
syscall #display enterD
addi $v0, $0, 5 #store input instr to v0
syscall # Get divisor
add $a1, $0, $v0 # Divisor to $a1
#end snippet发布于 2015-10-08 11:08:36
下面是有问题的代码:
lui $a1, 0x1001 #Where I think the problem is...
#Address of first string followed by add offset?
addi $a1, $a1, 33 #Maybe incorrect offset?$a0中,而不是$a1中。promptD的NUL-结束符字节位于0x10010010,而enterD字符串从0x10011开始(如果很难读取十六进制ASCII代码,可以在数据段查看器中的"ASCII“复选框中勾选”ASCII“复选框,以将数据视为字符)。所以您应该使用的偏移量是0x11 (十进制17)。https://stackoverflow.com/questions/33006978
复制相似问题