Skip to main content

Breakdown the jump instruction 0xfe1ff0ef ?

Steps

  1. Convert to binary representation
  2. Extract the imm fields
  3. Reorganize and concatenate
  4. Perform 2s complement conversion (if -ve need additional steps like example here, if positive just read out number in binary).

Instruction in Binary (Bits 31 to 0)

First, convert each hexadecimal digit to its 4-bit binary equivalent and write them in order:

Hexadecimal to Binary Conversion:

Hex Binary
f 1111
e 1110
1 0001
f 1111
f 1111
0 0000
e 1110
f 1111

Combined Binary Instruction:

#### **Binary Representation**
Bit Position [31] [30] [29] [28] [27] [26] [25] [24] [23] [22] [21] [20] [19] [18] [17] [16] [15] [14] [13] [12] [11] [10] [9] [8] [7] [6] [5] [4] [3] [2] [1] [0]
Binary Value 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 1 1 1

Grouped by Fields

Field Bits Binary Value
imm[20] [31] 1
imm[10:1] [30‒21] 1 1 1 1 1 1 1 0 0 0
imm[11] [20] 1
imm[19:12] [19‒12] 1 1 1 1 1 1 1 1
rd [11‒7] 0 0 0 0 1
opcode [6‒0] 1 1 0 1 1 1 1

Field Breakdown

The RISC-V JAL instruction format divides the 32-bit instruction into the following fields:

  • imm[20]: Bit [31]
  • imm[10:1]: Bits [30:21]
  • imm[11]: Bit [20]
  • imm[19:12]: Bits [19:12]
  • rd: Bits [11:7]
  • opcode: Bits [6:0]

Detailed Breakdown:

  • Opcode (bits [6:0]): 1 1 0 1 1 1 1 (binary) = 0x6F (hexadecimal)

    • Instruction: JAL (Jump and Link)
  • Destination Register (rd) (bits [11:7]): 0 0 0 0 1 (binary) = 1 (decimal)

    • Destination Register: x1
  • Immediate Fields:

    • imm[20] (bit [31]): 1
    • imm[10:1] (bits [30:21]): 1 1 1 1 1 1 1 0 0 0
    • imm[11] (bit [20]): 1
    • imm[19:12] (bits [19:12]): 1 1 1 1 1 1 1 1

Immediate Value Reconstruction

To reconstruct the immediate value, we rearrange the bits according to the JAL instruction format:

Immediate[20]    Immediate[10:1]     Immediate[11]    Immediate[19:12]
     1        | 1 1 1 1 1 1 1 0 0 0 |      1        | 1 1 1 1 1 1 1 1

Combined Immediate Bits (before shifting):

Immediate[20:1]: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0

Note: The immediate value is left-shifted by 1 (since the address is word-aligned), so we append a 0 at the end.

Final Immediate Value (21 bits):

Immediate[20:0]: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0
  • Since the MSB is a 1, the immediate value is negative. It represents -offset.
  • Thus, we first figure out what +offset is in decimal and then apply the negative sign.
  • To find out what +offset is we apply the following steps in binary form. -(-offset) = ~offset + 1

Calculating the Offset (Two's Complement)

Since the most significant bit is 1, the immediate value is negative.

  • Two's Complement Calculation:

    1. Invert the Bits:

      Inverted: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1
      
    2. Add 1:

      Two's Complement Value: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
      
  • Convert to Decimal:

    Binary: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
    Decimal Value: 32
    
  • Apply Negative Sign:

    Offset = -32 bytes
    

Final Disassembled Instruction

jal x1, -32

Breakdown the branch instruction 0xfecd80e3

This detailed breakdown shows the step-by-step disassembly of the branch instruction , including the binary conversion, field extraction, immediate value calculation, and the final assembly instruction.

Instruction Breakdown Table

Bit Position [31] [30] [29] [28] [27] [26] [25] [24] [23] [22] [21] [20] [19] [18] [17] [16] [15] [14] [13] [12] [11] [10] [9] [8] [7] [6] [5] [4] [3] [2] [1] [0]
Binary Value 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1

Field Breakdown Table

Field Bits Binary Value Description
opcode [6:0] 1 1 0 0 0 1 1 Opcode (0x63)
funct3 [14:12] 0 0 0 Function (BEQ)
rs1 [19:15] 1 1 0 1 1 Source Register 1 (x27)
rs2 [24:20] 0 1 1 0 0 Source Register 2 (x12)
imm[12] [31] 1 Immediate bit 12
imm[10:5] [30:25] 1 1 1 1 1 1 Immediate bits 10:5
imm[4:1] [11:8] 0 0 0 0 Immediate bits 4:1
imm[11] [7] 1 Immediate bit 11

Immediate Value Reconstruction

Immediate Bits in Order:

Immediate Bit Value Source Bit Position
[12] 1 [31]
[11] 1 [7]
[10] 1 [30]
[9] 1 [29]
[8] 1 [28]
[7] 1 [27]
[6] 1 [26]
[5] 1 [25]
[4] 0 [11]
[3] 0 [10]
[2] 0 [9]
[1] 0 [8]
[0] 0 (After shifting left)

Immediate Binary Value (After Shifting Left by 1):

Immediate[12:0]: 1 1 1 1 1 1 1 1 0 0 0 0 0

Calculating Offset:

  • Two's Complement:

    Inverted: 0 0 0 0 0 0 0 0 1 1 1 1 1
    Add 1:    +                             1
               -----------------------------
               0 0 0 0 0 0 0 1 0 0 0 0 0
    
  • Decimal Value: 32

  • Offset: -32 bytes

Final Disassembled Instruction

beq x27, x12, -32