So far I've written one assembly program that didn't use data memory at all. Now I'm trying to write a super simple program that stores a value then loads that value into a different register (and prints things to make sure I'm sane).
li $t0, 13 # data that I want to store
li $v0, 1
move $a0, $t0
syscall
sw $t0, 0($zero) # error
#lw $t1, 32
#li $v0, 1
#move $a0, $t1
#syscall
I keep getting an 'address out of range' error. I've tried changing the offset to different values (4, 8, 32) and even tried loading immediates into a register so I'm not using the $zero register.
What do I use as a base address if all my program has is data? What is wrong with storing a data value at address zero? My textbook/brain lead me to believe that this was absolutely fine..
That's because there is no memory mapped to address 0. It is most likely somewhere after 0x10000000, (usually 0x10010000 in MARS) in which you will see when you look at the data segment window of the simulator.
So, if you want to access a word at the beginning of the data segment, put a label
ie:
.data
startofdata: .word 0
and in the code section:
la $a0, startofdata
sw $t0, 0($a0)
startdata could be named error, if you wanted to label each location to make it more readable