Your first program
The toolkit includesmain.4004, a demonstration program that implements a basic interactive shell. Let’s build and run it.
Assemble the program
Use the assembler to convert the If assembly succeeds, you’ll have a new file
.4004 source file into an executable binary:The assembler takes two arguments: the input assembly file and the output executable file path.
4004-asm/main.4004out containing the compiled program.Run the emulator
Launch the emulator with your compiled program:The emulator loads the executable into program memory and begins execution.
Interact with the shell
You should see a
$ prompt. The shell is now waiting for your input.Try the echo command:All in one command
You can also run all three steps in sequence:- Builds the toolkit (if needed)
- Assembles the example program
- Runs it in the emulator
Assembler usage
The assembler follows this syntax:<input.4004>- Path to your Intel 4004 assembly source file<output_binary>- Path where the assembled executable will be written
Emulator usage
The emulator follows this syntax:<executable>- Path to a compiled 4004 program (output from the assembler)
Understanding main.4004
The example program demonstrates several features of the Intel 4004:Memory allocation
Implements a
MALLOC function that allocates memory from a heapStack operations
Custom stack implementation using data RAM with push/pop operations
I/O handling
Reads from virtual keyboard and writes to virtual monitor via ROM ports
Command parsing
Parses command-line arguments and recognizes the
echo commandWhat’s happening under the hood
When you run the emulator:- The 4004 CPU starts at address 0 in program memory
- The program initializes the stack counter and memory allocator
- It prints the
$prompt to the monitor - The keyboard polling loop waits for your input
- When you press Enter, it parses your command and executes it
- The cycle repeats
Next steps
Now that you’ve run your first program, explore:- Study the
4004-asm/main.4004source to learn the assembly syntax - Read about the assembler’s convenience features
- Learn the Intel 4004 instruction set
- Write your own 4004 programs