【发布时间】:2016-05-26 13:05:16
【问题描述】:
我正在尝试编写一个接受 2 个输入的程序,将它们存储在寄存器中,然后将这些寄存器存储在数据段中。
.data
val1: .word 1
val2: .word 2
val3: .word 3
.asciiz "Branden"
.asciiz "Enter a number "
.asciiz "\n"
.globl main
.text
main:
addi $s0, $0, 23 # initializes the register $s0 to 23
lui $a0, 0x1001
ori $a0, $a0, 20 #outputs string that is at 20
ori $v0, $0, 4 #command for output
syscall
addi $v0, $0, 5 # asks for input
syscall
addi $s1, $v0, 0 # set the value of $s1 as the given input
lui $a0, 0x1001
ori $a0, $a0, 20 #outputs string that is at 20
ori $v0, $0, 4 #command for output
syscall
addi $v0, $0, 5 #asks for input
syscall
addi $s2, $v0, 0 # set the value of $s2 as the given input
sw $s1, 0($t0) # store the value of $s1 into data segment val1
sw $s2, 4($t0) # store the value of $s2 into data segment val2
ori $v0, $0, 10
syscall
问题是我收到此错误:C:\Users\Danny\MIPS\assignment1.asm 第 34 行错误:0x0040003c 处的运行时异常:地址超出范围 0x00000000
错误发生在 sw $s1, 0($t0) 行,但原因是什么?是否需要与 sw 关联的 lw?
【问题讨论】:
-
崩溃时t0寄存器里有什么?我没有看到你设置它,所以大概是 0?可能不是正确的答案。
-
那么将它存储到 val1 中的正确格式是什么?我应该使用 lw 将 val1 存储到 $t0 中吗? @DavidWohlferd
-
我注意到你正在做一堆
lui, ori序列。你可以使用伪操作(例如la、li)吗?此外,您正在硬连线偏移到您的.asciiz字符串。每个人都应该有自己的标签。例如,如果我们将.asciiz "Branden"更改为.asciiz "brandenfam",您的打印字符串系统调用将中断。 -
不,不幸的是我不能使用 la 或 li @CraigEstey