Reputation: 145
.data
strA: .asciiz "Original Array:\n"
strB: .asciiz "Second Array:\n:"
newline: .asciiz "\n"
space : .asciiz " "
# This is the start of the original array.
Original: .word 200, 270, 250, 100
.word 205, 230, 105, 235
.word 190, 95, 90, 205
.word 80, 205, 110, 215
# The next statement allocates room for the other array.
# The array takes up 4*16=64 bytes.
#
Second: .space 64
.align 2
.globl main
.text
main:
la $t0, Original #load address of original array
li $v0, 4 #system call code for printing
la $a0, strA
syscall
addi $t1, $zero,0
sll $t2, $t1, 2
add $t3, $t2, $t1
li $v0, 4
lw $a0, 0($t3)
syscall
I am trying to make a program that transposes a matrix. However I keep getting an error saying bad address read: 0x00000000. I tried loading the addresses of the matrix and then loading 0 into $t1 for the beginning index and then multiplying that by four and adding it to the base address of the array.
As you can see I have loaded the address of the array and also added the i*4 amount with sll. Why am I getting this error?
Upvotes: 1
Views: 8277
Reputation: 58507
System call 4 prints a string. If you want to print an array of integers you'll have to write a loop and use system call 1 (print_int
) for each integer in the array.
The exception occurs at lw $a0, 0($t3)
, and if you look at the way you set up $t3
it should be obvious that it couldn't have any other value than 0, so I'm not sure what you expected to happen there.
I'm assuming that you're using a simulator like SPIM or MARS, so you can easily find out these kinds of things yourself. The simulator will report the address at which the exception occurs, so you can just set a breakpoint at that address (or single-step up until that address) and look at the values of the registers to see if they make sense.
Upvotes: 2