0
votes

I am trying to execute a very simple program but I keep getting the error :Invalid language element

lw $t0, 0($a0)               #load integer from $a0->$t0
beq $t0, 1, 1dimensional     #branch if $t0=1

1dimensional:
do something

I cant understand why I am getting the error.

1
mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html says BEQ takes two register operands and a label, not an immediate. - Peter Cordes
@PeterCordes Using an immediate as the second argument is valid, because beq is a pseudo-op [if the assembler suports it, which mars does]. It generates the following "real" instruction sequence: addi $at,$zero,1 / beq $at,$t0,1dimensional. - Craig Estey
Ah, ok, then not a duplicate of stackoverflow.com/questions/16760255/… after all, if you use an assembler which will destroy $r1 for you while expanding beq as a pseudo-op. That seems really weird to me, but I guess when you have 31 architectural registers, it's "ok" to waste some of them, like the two that the OS is allowed to clobber asynchronously. - Peter Cordes
$1 is the "assembler temporary" ($at), which is used by some pseudo-instructions to hold an intermediate result. It's fine to use it as a regular GPR if you avoid pseudo-instructions, or make sure that you don't rely on its value being preserved across any pseudo-instruction usage. - Michael

1 Answers

2
votes

You left out a crucial part of the error message, namely what the invalid language element was.
What the assembler is complaining about is the label 1dimensional. It's common for assemblers to only allow letters and underscores (and possibly a single .) as the first character of a label. So change the name of that label to something that meets that requirement, e.g. onedimensional.