MIPS将数据保存在阵列中 [英] MIPS saving data in arrays
本文介绍了MIPS将数据保存在阵列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行程序时出现错误:存储地址未与单词边界对齐,我应该怎么办?
代码如下:
.data
welcome: .asciiz "Welcome to Memorization Game.
Your need to enter the numbers printed in the exact sequence. Press S to start.
"
start: .asciiz "
Here we go....
"
enter: .asciiz "
Please enter the number:
"
array: .space 400
.text
main: la $t0, array # load address of array
la $a0, welcome
li $v0, 4 #
syscall # print welcome message
li $v0, 12 #
syscall # scan to continue
bne $v0, 115, Exit # if $v0 != "s", jump to Exit
la $a0, start #
li $v0, 4 #
syscall # Print start message
li $s0, 0 # N0. of random generated numbers = 0
add $t3, $t0, $0 # load address of array into $t3
Random: slti $t2, $s0, 100 #
beqz $t2, Exit #
addi $a0, $zero, 10 #
addi $a1, $zero, 99 #
li $v0, 42 #
syscall # generate a random number
sw $v0, ($t3) # put number generated into array[n]
addi $t3, $t3, 4 # next address
addi $s0, $s0, 1 # counter++
j Random
Exit: li $v0, 10 #
syscall # terminate
推荐答案
尝试在array: .space 400
之前插入以下内容之一:
.p2align 2
 ;
.align 2
 ;
.align 4
另一个可能的选择是将array: .space 400
移动到数据节的开头。
这篇关于MIPS将数据保存在阵列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文