MIPS Assembly Labels

dbarcklow

Does assembly for MIPS read every label? ignore the task and syntax, I just put something together quick.

add reg3, reg1, $zero
add reg1, reg1, reg2
beq reg1, reg3, BRANCH1      #reg2 contents are zero
bne reg1, $zero, BRANCH2     #reg1 doesn't equal zero
BRANCH1: add returnReg, reg1, $zero
BRANCH2: add returnReg, reg2, $zero
jr returnAddress

would this read line-by-line, including the labels, unless they were jumped over? For instance, would BRANCH1 be executed every single time, unless the contents of reg1 are equal to zero?

From wiki: A label is something to make your life simple. When you reference a piece of your program, instead of having to count lines, you can just give it a name You use this in loops, jumps, and variable names. Labels don't appear in your final code, they're only there for convenience, one of the few perks you'll get from the typical MIPS assembler. It also makes life easy for the assembler, because it can now easily go around relocating and linking code. Don't worry if you don't know what those are, that'll come later.

From this, I take that labels are nothing more than a line reference. Which means that jumping around the code (using bne, beq, jr, j, etc.) is the only way to prevent an instruction on a certain line to be read. Is this correct thinking?

Rob

Labels are only so you can reference the line with a jump. The CPU itself will only see the machine code. The same is true of any comments in your code. They are only there in the assembler - this is then converted into machine code.

You will need to jump over a line if you don't want it executing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related