Reputation: 36
Any ideas why I'm getting an alignment error? The error happens when executing la $t0, mainF
, even though the similar line la $t0, mainB
executes just fine. This is my first time coding in MIPS so I did some research and have a vague idea of what the address alignment means, but the compiler doesn't even get to the part where I add 4 before throwing me this runtime exception.
.data
mainF:
.byte 1
mainB:
.byte 1
mainN:
(has '.word's, generic tests for the program itself)
newline:
.asciiz "\n"
textFw:
.asciiz "The integers in order:\n"
textBw:
.asciiz "The integers in backwards order:\n"
.text
main:
# Function prologue
addiu $sp, $sp, -24 # allocate stack space -- default of 24 here
sw $fp, 0($sp) # save caller's frame pointer
sw $ra, 4($sp) # save return address
addiu $fp, $sp, 20 # setup main's frame pointer
# Put mainF into $s0
la $t0, mainF
lw $s0, 0($t0)
# Put mainB into $s1
la $t0, mainB
lw $s1, 0($t0)
...
Upvotes: 1
Views: 4019
Reputation: 86718
You have the following declarations:
mainF:
.byte 1
mainB:
.byte 1
Assuming that mainF
gets assigned the address 0
, mainB
will get assigned the address 1
. Since the address 1
is clearly not word-aligned (i.e. 1 is not a multiple of 4), attempting to load it will cause an exception.
Upvotes: 2