L03_Loops and Arrays in MIPS

L03_Loops and Arrays in MIPS - Branches Two branch...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Two branch instructions: beq $t0, $t1, label # if t0 == t1, jump to “label” bne $t0, $t1, label # if t0 != t1, jump to “label” For branch instructions, the constant field is not an address, but an offset from the current program counter (PC) to the target address. beq $t0, $t1, EQ add $t0, $t0, $t1 addi $t1, $t0, $0 EQ: add $v1, $v0, $v0 Since the branch target EQ is three instructions past the beq , the address field contains 3 Branches 000100 10001 10010 0000 0000 0000 0011 op rs rt address (offset)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 J-type format In most programs, branch targets are less than 32,767 instructions away — branches are mostly used in loops and conditionals — programmers are taught to make loop bodies short For “far” jumps, use j and jal instructions ( J-type instruction format) — address is always a multiple of 4 (32 bits per instruction) — only the top 26 bits actually stored (last two are always 0) For even longer jumps, the jump register ( jr ) instruction can be used. jr $ra # Jump to 32-bit address in register $ra opcode address (exact) 6 bits 26 bits
Background image of page 2
3 The MIPS processor only supports two branch instructions, beq and bne , but to simplify your life the assembler provides the following other branches: blt $t0, $t1, L1 // Branch if $t0 < $t1 ble $t0, $t1, L2 // Branch if $t0 <= $t1 bgt $t0, $t1, L3 // Branch if $t0 > $t1 bge $t0, $t1, L4 // Branch if $t0 >= $t1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

L03_Loops and Arrays in MIPS - Branches Two branch...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online