0

Using this code I get store address not aligned on word boundary 0x10010002. I want to initialise an array with zeroes, what am I doing wrong in storing the value (word) 0 inside the each element? While debugging I have seen that the problem starts at sw part and the program enters the loop just once.

.data
    hash:   .space  40
    N:      .word   10

.text
.globl main

main:

    lw  $s0,    N       # N = 10 

    addi    $t4,    $zero,  0   # $t4 = 0 (for counter)
    addi    $t5,    $zero,  0   # $t5 = 0 (index for array, adds 4 every time)
    addi    $t6,    $zero,  0   # $t6 = 0 (used for filling array, never changes)

for:    
    bge $t4,    $s0,    terminate

    sw      $t6,    hash($t5)

    addi    $t5,    $t5,    4
    addi    $t4,    $t4,    1

    j   for


terminate:

    li $v0,10
    syscall

The $t4 counter is adding 4 bytes to itself because the array is going to have integers. Please let me know if you can see where my mistake is in this simple example, I tried to make it as simple as possible.

I am using MARS 4.5

  • Presumably `hash` isn't word aligned. Add whatever alignment directive your assembler (that you unfortunately didn't specify) supports. – Jester Dec 13 '19 at 17:28
  • @Jester I am using MARS 4.5 (post updated) – Dimitrios Filippou Dec 13 '19 at 17:41
  • Insert `.align 2` on the line before the `hash: .space 40` – Jester Dec 13 '19 at 17:45
  • @Jester worked! can you provide a link for this? – Dimitrios Filippou Dec 13 '19 at 17:50
  • 1
    Don't know the location of the official MARS manual, but you can find plenty of materials using google, such as [this](http://www.ccs.neu.edu/home/kapil/courses/cs5600f18/mars.html) – Jester Dec 13 '19 at 17:51
  • @Jester thanks! you can also provide an answer if you wish – Dimitrios Filippou Dec 13 '19 at 17:54
  • 1
    You used a generic `.space` directive, meant to allocate bytes to allocate words. Though the multiple 40 will allocate 10 words, `.space` doesn't know about alignment, the content the way `.word` does. So, use `.align` in conjunction with `.space` for allocating empty space for shorts or ints or floats or doubles. – Erik Eidt Dec 13 '19 at 20:54
  • Also [Error: Runtime exception ... store address not aligned on word boundary](https://stackoverflow.com/q/45174399) – Peter Cordes Mar 21 '20 at 03:00

0 Answers0