【发布时间】:2025-12-20 22:50:11
【问题描述】:
我在运行程序时遇到错误:存储地址未对齐字边界,我该怎么办?
代码如下:
.data
welcome: .asciiz "Welcome to Memorization Game. \n\nYour need to enter the numbers printed in the exact sequence. Press S to start.\n"
start: .asciiz "\nHere we go....\n"
enter: .asciiz "\n Please enter the number:\n"
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
【问题讨论】:
-
更多详细信息:
.align如何在经典 MIPS 汇编器中工作(MARS/SPIM 遵循,与 clang 和针对 MIPS 的 GNU 汇编器不同):MIPS Assembly Alignment Align n
标签: arrays assembly mips memory-alignment memory-address