MIPS Bad Address in data stack

0

I'm just starting out in MIPS. I have an assignment as follows:

Count the number of multiples of X in a given array of 8 non-negative numbers, where X is a user chosen power-of-two value, e.g. 1, 2, 4, 8, ….

Write the necessary code to:

a. Read user input value, X. You can assume X is always a power-of-two integer, i.e. there is no need to check for invalid user input.

b. Count the number of multiples of X in arrayA and print the result on screen.

For this set of input given in the code, I'm trying to get my output to be

2
3

However, I have the following error: "Bad address in data/stack read: 0x00000090"

I'm using QTSpim simulator and this is the data segment information. May I know how is 0x00000090 not the memory location of the first element of the array I'm trying to access? This code may not achieve the desired output because I'm stuck at this stage of debugging.

enter image description here

# arrayCount.asm
  .data 
arrayA: .word 11, 0, 31, 22, 9, 17, 6, 9   # arrayA has 8 values
count:  .word 999             
char: .ascii "\n"

  .text
main:
    # code to setup the variable mappings
    la $t0, 144 #map arrayA
    la $t8, 146 #map count

    # code for reading in the user value X
    li  $v0, 5
    addu $a1, $v0, -3 
    syscall

    #start printing out the stored int here 
    li  $v0, 1
    addu $a0, $a1, $zero
    syscall

    #print newline character(Assuming string)
    li  $v0, 4
    la  $a0, char
    syscall

    #to set the higher bound to do a while loop
    li  $a0, 8
    addi $t2, $zero, 0 


    # code for counting multiples of X in arrayA


loop:
    slt $t1, $t2, $a0
    beq $t1, $zero, exit

    sll $t3, $t2, 2
    add $t4, $t3, $t0
    lw $t5, 0($t4)
    and $t6, $t5, $a1

    beq $t6, $zero, skip
    addi $t8, $t8, 1

skip:
    addi $t2, $t2, 1 
    j loop    

exit:

    # code for printing result

    li  $v0, 1
    addu $a0, $t8, $zero
    syscall

    # code for terminating program
    li  $v0, 10
    syscall
assembly
mips
qtspim

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0