【发布时间】:2019-11-21 19:33:48
【问题描述】:
我的问题是;如何在不创建数组的情况下将多个用户输入的输入存储到变量中?当我运行我在此处发布的代码时,我收到错误“存储地址未在字边界上对齐”。变量一是store1,变量二是store2。我想将两个单独输入的整数分别存储到 store1 和 store2 中。
.data
store1: .byte 4 #Stores data entered by user
store2: .byte 4 # " "
msg: .asciiz "Enter your first decimal number: "
msg2: .asciiz "Enter your second decimal number: "
.text
main:
la $a0, msg #Displays msg
li $v0, 4
syscall
li $v0, 5 #Prompts user to enter an integer
syscall
la $t0, store1 #Loads user input into store1
sw $v0, store1 #Stores user input into store1
la $a0, msg2 #Displays msg2
li $v0, 4
syscall
li $v0, 5 #Prompts user to enter another integer
syscall
la $t1, store2 #My error occurs here
sw $v0, store2 #If I delete these 3 lines the code compiles with no errors
syscall
li $v0, 10 #Cleanly exits the program
syscall
【问题讨论】:
-
你只分配了一个字节。如果您打算存储字节,请使用
sb而不是sw。相反,如果您想要单词,请使用.int或 mars 中的任何等效项。 -
明白。使用
sb更正了该问题。以及将.byte 4更改为.int 0感谢您的帮助。
标签: assembly memory mips mars-simulator