Assembly Language Fundamentals

Beginner
Version:
1.1

Jump (JP)

Introduction

Previously you learned how to load values, print letters, and do basic addition. Now it’s time to take more control of how your program executes. This lesson introduces a new concept: Flow Control, specifically, how to jump around inside your program using the JP instruction

What Does JP Do?

JP stands for Jump.

The Z80 normally reads instructions one after another in sequence. The JP instruction interrupts that flow and tells the CPU:

“Stop reading the next instruction, and instead jump to a specific address and continue from there.”

This gives you control to:

In future lessons, you’ll see conditional jumps, where the jump only happens if certain conditions are true

Example Program: Using JP to Skip Instructions

        ORG 256
        LD A, 83         ; Load ASCII 'S'
        JP 262           ; Skip the RET
        RET              ; This line is skipped
        RST 8
        DEFB 158
        RET

Walkthrough

How the Program Assembles in Memory

If the program started at 256, why does it jump to 258 after just one instruction? It’s because the address is counting individual bytes. When you assemble your program, each instruction is translated into one or more bytes of machine code. These bytes are then placed sequentially in memory, starting from the program’s load address. The first instruction ‘LD A, 83’ is two object codes, two bytes, so the address increases by two. Here’s how your example looks once assembled:

Assembly Breakdown

Object Codes

When you write an assembly program, each instruction is translated into object code — the actual machine instructions that the processor runs. These are written as hexadecimal values, which is how we humans usually represent machine code bytes.

Here’s what that looks like for your example program:

Why This Matters

Understanding how assembly instructions translate into object code is an important skill. It helps you:

The Program Counter (PC)

The Program Counter (PC) is a register that stores the address of the current instruction.

So:

JP 262 means “Set PC to 262 and continue from there.”

Finding the Right Address for JP

There are two methods for find the specific address to jump to:

Option 1: Manual Calculation
You would calculate the quantity of object codes / bytes manually 

 If ORG 256:

Option 2: Use z80asm Listing File

You could you the z80asm command line tool output the .com program along with all the memory address locations.

z80asm -l -o program.com program.asm > program.lst

Output shows addresses like 0106 (hex) = 262 (decimal). This is the most reliable method for larger programs

Don’t Worry

In reality, when wiring assembly code, you’ll be using concepts like Labels, Subroutines, and Jump Relative. So you probably won’t need to manually calculate specific memory address to use with the JP instruction.

Exercises

Exercise 2.1 – Jump To It
Write a program that:

  1. Loads a value into A.
  2. Uses JP to skip a RET.
  3. Prints the value with RST 8 and DEFB 158.
  4. Ends with RET.

Then try:

Summary

Previous Module
Next Module