-1

So I am using QtSpim to run my mips program for school. I basically made a working program, but now i keep getting an exception error. I've tried cutting down my code, so here is where the error starts now.

.text
.globl main
main:
.data 
    message1: .asciiz "The maximum is "
    message2: .asciiz "The summation is "
    myArray: .space 32
.text
    addi $s0, $zero, 11
    addi $s1, $zero, 12
    addi $s2, $zero, -10
    addi $s3, $zero, 13
    addi $s4, $zero, 9
    #addi $s5, $zero, 12 not needed
    addi $s5, $zero, 14
    addi $s6, $zero, 15
    addi $s7, $zero, -20

    addi $t0, $zero, 0

    sw $s0, myArray($t0)
    addi $t0, $t0, 4

    li $v0,10
    syscall

The error is sw $s0, myArray($t0)

sarah campolt
  • 148
  • 2
  • 13

1 Answers1

0

You likely need to make sure myArray is aligned to a 32-bit boundary. I suggest trying a .align directive before its declaration.

Zalman Stern
  • 3,161
  • 12
  • 18
  • I changed the code to myArray: .align 32 .space 32 But I still get the same error – sarah campolt Oct 18 '17 at 23:31
  • Pretty sure the .align needs to go before the label. Perhaps see: https://stackoverflow.com/questions/19608845/understanding-assembly-mips-align-and-memory-addressing – Zalman Stern Oct 18 '17 at 23:35
  • I have it as .align 32 then my Array: .space 32, but I still got the same error – sarah campolt Oct 18 '17 at 23:37
  • I mentioned alignment as this would change when adding the second message string before the myArray declaration and it is a reason the sw instruction might go from working to faulting. Either the assembler is turning the sw into more than one instruction, using a temp register, or there is a requirement that myArray is in the low 64k of memory. It should be easy to debug if you can get the register values and the faulting instruction, and possibly the specific exception type. I.e. make sure it is the sw that is faulting. Calling functions may require saving caller save registers as well. – Zalman Stern Oct 18 '17 at 23:48
  • In a normal assembler, `.align` would need to go before the label. In classic MIPS assemblers, `.align` can magically affect the previous label, if you put it after a label but before `.space` or something. [MARS MIPS simulator's built-in assembler aligns more than requested?](https://stackoverflow.com/q/59926448) I'd still recommend putting it *before* a label you want to align, though, so you can think of it as simply emitting bytes at the current location until the position reaches the alignment boundary. – Peter Cordes Apr 10 '22 at 19:59