label execution in MIPS
This is a really easy question, but if I have a bunch of instructions written for MIPS (although I assume this probably carries over to assembly in general), and there is a label at some point, does the instruction at that label get executed even if it's not explicitly called? For instance, let's say I have:
SUB $6, $4, $3
BNE $6, $2, LA开发者_JAVA百科BEL1
ADDI $6, $0, -8
LABEL1: SW $6, 0x01000
If the BNE
branches to LABEL1, then the ADDI gets skipped. But if BNE doesn't branch to LABEL1, then the ADDI happens, but does the next line always happen too?
It is called the delay slot. The branch is performed or not after the following instruction is executed. This is why it is common to see a nop
after branch instructions in MIPS code. A branch instruction in the delay slot is usually undefined behavior.
The instruction at the destination label will only be executed if the condition is true and the branch is taken.
More information here
"does the next line always happen too?"
yes
精彩评论