Reputation: 307
I'm trying to solve a small assignment question using MARS, but I keep getting this error. Is there something that I did wrong?
I'm getting the error at linenum 11: which is lw $t0, 0
Below is the code of my program.
.data
SOURCE: .word 0x0100
DEST: .word 0x0110
.text
lw $t0, 0
lw $t4 , -1
lw $t5 , 0
lw $t6, 20
lw $t7, 32
VERY_START:
beq $t6,$zero,EXIT
addi $t6,$t6,-1
lw $t7,32
la $t1,SOURCE
li $t2,1
li $s1,2
START:
and $t3, $t2 , $t1
beq $t4,-1,FIRST_LOOP
bne $t4,$t3,STORE
#bne is branch if not equal to.
add $t5 , $t5 , 1
addi $t7, $t7 , -1
beq $t7, $zero, VERY_START
# So we jump to the very start if we have 32 bits done.
sll $t2, $t2 , 1
j START
STORE:
sb $t5,DEST($t2)
#dest needs to be defined (It is implicit according to the question)
# after storing , we need to increment $t0 so that we can store the next element a byte away from this one. so
add $t0 , $t0 , 2
lw $t5,1
addi $t7, $t7 , -1
beq $t7, $zero, VERY_START
# So we jump to the very start if we have 32 bits done.
sll $t2, $t2 , 1
j START
FIRST_LOOP:
# we populate t4 here
move $t4,$t3
j START
EXIT:
#we find the number of counts by simply dividing the current t0 with 2
div $t0, $s1
mflo $t0
# we move the quotient to t0..
move $a0,$t0
li $v0, 1
syscall
Upvotes: 1
Views: 9138
Reputation: 520878
According to this reference, you are trying to load a literal into a register using lw
, which is not allowed:
RAM access only allowed with load and store instructions
You have two choices:
Option 1
You can load into $t0
from temporary storage
var1: .word 0 # declare storage for var1; initial value is 0
.text
lw $t0, var1 # load contents of RAM location into register $t0: $t0 = var1
...
Option 2
You can use li
load immediate using a literal value
li $t0, 0 # $t0 = 0 ("load immediate")
You have this problem in several places in your code.
Upvotes: 1