Skip to main content

What is the offset for 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 0 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 0 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[19:12] | Immediate[11] |   Immediate[10:1]   |     
     1         | 1 1 1 1 1 1 1 1 |      1.        |  1 1 1 1 1 1 0 0 0 0 |             

Combined Immediate Bits (after shifting):

Immediate[20:0]: 1 1 1 1  1 1 1 1 1  1 1 1 1 1  1 0 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.

  • 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

This horizontal representation shows each bit and its corresponding field, providing a clear view of the instruction’s structure.