#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    [Assmbly] Getting an exception when storing a word


    I'm using QtSpim, and trying to create a nested for loop, and I put in this code:

    .data
    .text
    .globl main

    main: addi $t0, $zero, 0 #t0=i

    StartOne:
    addi $t1, $zero, 0 #t1=j
    addi $s3, $zero, 0 # reset index of s3, s3 is array d
    StartTwo:
    add $t2, $t0, $t1
    sw $t2, 0($s3)
    addi $s3, $s3, 16
    addi $t1, $t1, 1


    blt $t1, $s1, StartTwo # $s1=b
    addi $t0, $t0, 1
    blt $t0, $s0, StartOne # $s0=a
    jr $ra

    Then, in the int regs column, I set $s0 to 10, and $s1 to 5, and $s3 to 10000000, then I load the code. When I run the code step-by-step, at the first iteration of the inner loop, I get a message that an exception occured at PC=0*00400034, which corresponds to the store word command, then, when I click OK, it says "Bad address in data/stack read: 0*00000000". Why am I getting this error?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    You're trying to write to memory location that doesn't belong to you (and address 0 is typically reserved as an illegal address anyway). Instead of setting $s3 to zero, reserve some memory in the .data section and store that address in $s3.

    (BTW the comments in your code might be the cause of some confusion--none of the appear to match what your code is actually doing)
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo