JR Offset Calculator
Compute the relative branch offset for JR (jump relative) style instructions. Enter decimal or hex values (examples: 4096, 0x1000, 1000h).
Most JR instructions use PC-relative math based on the address after the instruction, so offset = target - (current + instruction size).
What is a JR offset?
A JR offset is the signed distance from the next instruction to the jump target. In many CPUs (including retro and embedded systems), JR instructions do not store a full absolute address. Instead, they store a compact signed value that says “move forward or backward by N bytes.”
This design saves instruction space and improves code density, but it also means every jump must be within a legal range. For 8-bit signed JR, that range is usually -128 to +127.
How this calculator works
The formula used is:
offset = targetAddress - (currentAddress + instructionSize)
- currentAddress: where the JR instruction lives.
- instructionSize: number of bytes in that JR instruction.
- targetAddress: destination label address.
After computing the offset, the tool checks if it fits your selected signed width and shows the encoded two’s-complement value in hex and binary.
Why this matters in assembly programming
1) Prevent out-of-range jumps
The most common JR error is a jump that is “too far.” This is especially common after adding data tables, macros, or debug instructions. A quick offset calculation catches this before assemble time.
2) Verify hand-written machine code
If you are building ROM patches, game mods, or microcontroller boot stubs, you may need to confirm exact byte encodings. This calculator provides both signed value and encoded hex for direct verification.
3) Understand PC-relative behavior
Many developers new to low-level programming forget that JR is relative to the address after the instruction fetch. Internalizing this makes debugging disassembly much faster.
Quick example
Suppose:
- Current JR address =
0x1000 - Instruction size =
2bytes - Target =
0x101A
Then:
- Next instruction address =
0x1002 - Offset =
0x101A - 0x1002 = 0x18(decimal +24)
For 8-bit JR, +24 is valid and encodes as 0x18.
Common mistakes to avoid
- Using target - current instead of target - (current + instruction size).
- Assuming all jump instructions use the same offset width.
- Forgetting that negative offsets are two’s-complement encoded.
- Mixing decimal and hex accidentally while debugging.
Tips for cleaner branch logic
- Keep local branches close to reduce long-jump conversions.
- Use descriptive labels around loops and conditionals.
- Re-check JR distances after inserting constants or lookup tables.
- If range fails, swap to a wider branch/jump instruction when available.
Final note
This JR offset calculator is intended as a practical companion for assembly language study, reverse engineering, firmware work, and emulator development. It gives immediate feedback, reduces trial-and-error, and helps you reason clearly about branch encoding.