All tutorials

Intermediate · 25 min

Build a safe Z80 routine

Assemble, test and call a routine that changes the border and returns cleanly to BASIC.

STEP 01

Create the module

Open Machine Code Studio, set origin 32768 and entry label main.

ORG 32768

main:
    PUSH IY
    LD A,2
    OUT (254),A
    POP IY
    RET
STEP 02

Review the contract

Confirm the entry address, clobbered AF register, port 254 write and reachable RET.

STEP 03

Test before accepting

Run Test Routine and observe the return result. In the 1.6 runner, Pause and Continue retain CPU and RAM; Stop is inconclusive. A successful assembly is not yet an accepted CODE block.

STEP 04

Connect BASIC

Review the generated CLEAR, LOAD CODE and RANDOMIZE USR integration before applying it.

Z80 Machine Code Studio showing a finite counter routine paused after 20.14 simulated seconds, with instruction count, PC, Continue and Stop controls and an unaccepted assembly preview.
Pause without losing the machine state

The isolated counter test paused at PC $800B after 10,926,080 instructions. Continue resumes the test; accepting the assembled binary remains a separate decision.

Z80 Machine Code Studio showing assembly source, assembler preview and a passed 6150-instruction routine test.
Assemble. Test. Review.

A screen-clearing Z80 routine, its assembled listing and a passed routine test. Acceptance remains a separate action.

Expected result

Assemble, test and call a routine that changes the border and returns cleanly to BASIC.