Assembly Language Fundamentals

Beginner
Version:
1.1

Jump Relative (JR)

Introduction

In the last lesson, you learned how to jump to an absolute address using JP. This time, you’ll explore a different instruction: Jump Relative (JR).

JR is especially useful when writing loops and makes your programs far easier to read when combined with labels

What Is JR?

JR tells the CPU to jump a short distance forward or backward in memory relative to where it is now.

Key points:

If you’re repeating something small, JR is usually your best choice.

Infinite Loop Using JR

       ORG 256
       LD A, 83         ; Start with ASCII 'S'

loop:
       ADD A, 1         ; Keep increasing A
       JR loop          ; Jump back to the 'loop' label

What This Does

This results in an infinite loop. You’ll need to reset the emulator to stop it

Why Use Labels?

Previously, you might have written:

JP 262

That works, but if your program changes, the addresses change too, and you must recalculate them manually.

Using labels like this:

loop:
    JR loop

means the assembler automatically calculates the jump distance. This makes your code more flexible, readable, and error-proof. Thank goodness!

Important Notes About JR

Exercises

Exercise 3.1 — Start Small, Loop Forever

Write a program that:

  1. Loads A with 5
  2. Adds a value
  3. Loops back using JR
  4. Uses a label to make the loop readable
  5. Module3 - Jump Relative

Summary

Previous Module
Next Module