0
votes

I'm trying to make a program that calculates the following mathematical equation: A = B + C. B must be stored in memory, while C in a register.

So far I have done the following, but it doesn't work:

.set noreorder
.data 
    b: .word 20
    c: .word 10
.text
.globl main
.ent main

main:
    la $t0, b
    lw $a0, 0($t0)
    la $t1, c
    lw $a1, 0($t1)
    add $t9, $a0, $a1
.end main

Any help much appreciated. Thanks.

1
How "does it not work"? What error message or unexpected results do you get? - HBP
I get "ERROR: Illegal operands 'la'". Don't know what I am doing wrong. - Chris
Sounds like the la mnemonic is not being recognized. What assembler? - HBP
So you are saying that the code is correct? Would you not solve this differently? - Chris
The code does not look unreasonable. The syntax of assembly code can vary from assembler to assembler. Check your reference manual carefully to ensure you are using the correct mnemonics : la, lw etc. I have found not good reference to any assembler called mipslt - HBP

1 Answers

1
votes

Try:

.set noreorder
.data 
    B: .word 20
    C: .word 10
.text
.globl main
.ent main

main:
    la $t0, B
    lw $a0, 0($t0)
    la $t1, C
    lw $a1, 0($t1)
    add $t9, $a0, $a1
.end main

I have changed your code to use upper-case labels. This is because when I ran your code in the spim simulator I got this error: spim: (parser) Cannot use opcodes as labels on line 7 of file test.s.

b is actually the name of an instruction, so changing the names of the labels fixed the code for me.