Skip to content
BIASED

Branches, loops and memory access

Block 1 of 5~2 min

Branches and jumps

Computational instructions alone run straight-line code with data in 32 registers. Programs also need to choose, repeat, and touch more data than fits in registers. Without control flow a thousand numbers need two thousand instructions; without memory access every value must live in a register at once.

Notation. x[r]x[r] register rr; M[a]M[a] byte at aa; halfword = 2 bytes, word = 4. sext⁡\operatorname{sext} / zext⁡\operatorname{zext} widen by sign or zeros.

Conditional branches: beq, bne, blt, bge, bltu, bgeu — jump to a label (±4 KiB, B-format offset) if the condition holds, else fall through. bgt/ble and beqz/bnez/bltz/… are pseudos that swap operands or use zero. jal rd, label reaches ±1 MiB and links; j is jal zero, label.

Worked. t0=-1, t1=1: blt jumps; bltu does not (t0 as unsigned is 232−12^{32}-1). That unsigned reading catches both i ≥ n and negative i in one bgeu i, n, out_of_range.

Answers are saved on the server and tied to this browser until you sign in.