Z80 assembly: Text and console output
Load character codes into A. Send each byte to an output port.
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.
What happened
Program listing
| Address | Machine code | Label | Instruction | Comment |
|---|
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
| # | Address | Instruction | Result | T-states |
|---|
Console port or memory-mapped screen?
| Method | How it works | Depends on |
|---|---|---|
| OUT (n),A | Writes A to an I/O port | Computer’s port map |
| LD (HL),A | Writes A to a memory address | Computer’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
| Name | Stands for | Meaning here |
|---|---|---|
| LD | Load | Loads a character code into A. |
| OUT | Output | Sends A to an I/O port. |
| HALT | Halt | Stops after the text has been written. |
| ORG | Origin | Assembler directive. Sets the program address. |