Overview
This example demonstrates the basic workflow for Intel 4004 development:- Writing assembly code
- Assembling it into executable format
- Running it in the emulator
Create your assembly file
Create a new file called
hello.4004 with the following code:The
FIM instruction loads an immediate 8-bit value into a register pair. The #CALL macro is a convenience feature that handles function calls.Build the assembler
First, build the toolkit:This creates the assembler and emulator executables in
zig-out/bin/.Assemble your program
Convert your assembly code into an executable:This reads
hello.4004 and generates hello.4004out, which contains the assembled machine code.Understanding the code
The program uses several key concepts:Device I/O ports
The virtual monitor uses three I/O ports:- Port 3: First 4 bits of character
- Port 4: Second 4 bits of character
- Port 5: Ready signal (0 = ready, 1 = busy)
Register pairs
The Intel 4004 uses 4-bit registers (0R-15R) that can be grouped into pairs (0P-7P). Each pair holds 8 bits, perfect for representing a character.Convenience syntax
The assembler provides helpful extensions:FIM 0P 'H'- Load ASCII character into register pair#CALL PRINT_CHAR- Macro for function calls7P += 1- Increment register pairMONITOR_CHAR_PORT_1 -> 2R- Named constant assignment