BEQ

Branch if Equal

BEQ rs1, rs2, offset

Take the branch if registers rs1 and rs2 are equal.

Encoding

Binary Layout
bimm12hi
31:25
rs2
24:20
rs1
19:15
000
14:12
bimm12lo
11:7
1100011
6:0
 
Format B-Type
Opcode 0x00000063
Extension RV32I

Operands

  • rs1
    Source register 1 (integer)
  • rs2
    Source register 2 (integer)
  • offset
    PC-relative offset

Example

BEQ x5, x6, 100

// Jump to PC+100 if x5 == x6.

Related

Across architectures

Compare and Branch : how x86, ARM, RISC-V, and PowerISA each do this.

More in RV32I

Description

BEQ takes the branch if rs1 equals rs2. The branch target is the PC of the branch plus the sign-extended B-immediate, which encodes an offset in multiples of 2 bytes within a ±4 KiB range.

Operation

if (R[rs1] == R[rs2]) PC += sext(offset);