Steps
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 |
| 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 |
The RISC-V JAL instruction format divides the 32-bit instruction into the following fields:
Detailed Breakdown:
Opcode (bits [6:0]): 1 1 0 1 1 1 1 (binary) = 0x6F (hexadecimal)
JAL (Jump and Link)Destination Register (rd) (bits [11:7]): 0 0 0 0 1 (binary) = 1 (decimal)
x1Immediate Fields:
11 1 1 1 1 1 1 0 0 011 1 1 1 1 1 1 1To 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
1, the immediate value is negative. It represents -offset.Since the most significant bit is 1, the immediate value is negative.
Two's Complement Calculation:
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
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
jal x1, -32
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.
| 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 | 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 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
beq x27, x12, -32