Z80 assembly: Text and console output

Load character codes into A. Send each byte to an output port.

OUT (n),A

OUT sends a byte from A to an input/output port. A port is an address for a device outside normal memory. In this lesson’s simulator, port 00h writes one character to the console.

OUT (n),A is 2 bytes and takes 11 T-states. The Z80 does not define a universal console port. Real computers use their own hardware and port maps.

Run speed

What happened

Program listing

AddressMachine codeLabelInstructionComment

Each character is an ASCII byte. The program loads it into A, then writes A to port 00h. Each Step executes one instruction.

Registers and output

Flags

LD does not change flags. OUT does not change flags. PC is the Program Counter. A T-state is one CPU clock period.

Console output from port 00h

Execution trace

#AddressInstructionResultT-states

Console port or memory-mapped screen?

MethodHow it worksDepends on
OUT (n),AWrites A to an I/O portComputer’s port map
LD (HL),AWrites A to a memory addressComputer’s memory map

Some machines use dedicated ports. Other machines show text by writing character codes into a region of memory.

Port 00h is a teaching device in this simulator. It collects output bytes as text. This is not a standard Z80 hardware port.

Mnemonic glossary

Program mnemonics and directives
NameStands forMeaning here
LDLoadLoads a character code into A.
OUTOutputSends A to an I/O port.
HALTHaltStops after the text has been written.
ORGOriginAssembler directive. Sets the program address.