From 4b4a90a39a78746e0bd71e99b12cb42669af7698 Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat, 19 Oct 2024 21:25:45 +0200 Subject: [PATCH] add docs --- .gitignore | 1 + README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ cpu.c | 3 ++- makefile | 2 +- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f47cb20..5293f37 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.out +dumb8 diff --git a/README.md b/README.md index 16c7933..3b98406 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# UnnamedCPU +# Dumb8-CPU Continuing my exploration of the lower-level world... This project is the implementation of a CPU in a high-level language, C. It aims to have a reduced (minimalist) instruction set and still be Turing complete. -# How to test +## How to test You can run a test program like that. I'll try making a developer's manual so one can make its own programs using the custom assembly here. @@ -13,8 +13,48 @@ make ./a.out program.asm ``` -# What I'd like to do +## Technical specifications -- Finish the instruction set implementation -- Implement input/output devices (like a serial output that could be redirected to the host terminal) -- Re-do the CPU in a Hardware Description Language, or even better: with transistors IRL! (i probably won't waste my life doing that tho) +- 8-bit processing unit +- RISC (reduced instruction set computer) +- 4 general purpose registers (labeled R0 to R3) +- 1 input port, 1 output port (via getchar and putchar) +- Turing-completeness: bitwise and arithmetic operations + +## Instruction set reference (for programmers) + +``` +; Move register RY to register RX +MOV RX, RY + +; Arithmetic addition and substraction stored in RX +ADD RX, RY +SUB RX, RY + +; Bitwise operations stored in RX +OR RX, RY +AND RX, RY +XOR RX, RY + +; Output RX to screen +OUT RX + +; Input RX from keyboard +IN RX + +; Jump to memory offset ADDR (decimal) +JMP ADDR + +; Jump to memory offset ADDR (decimal) if equal flag is set by previous comparison +JEQ ADDR + +; Compare RX and RY, sets equal flag if true +CMP RX, RY + +; No operation; does nothing +NOP + +; Halts the processing unit +HLT + +``` diff --git a/cpu.c b/cpu.c index 8518bd4..6d8d102 100644 --- a/cpu.c +++ b/cpu.c @@ -1,5 +1,5 @@ /* - * Unnamed 8-bit processing unit + * Dumb8 8-bit processing unit * Made by github.com/xamidev * * This is free and unencumbered software released into the public domain. @@ -74,6 +74,7 @@ CPU_t cpu; void cpu_init() { + printf("Initializing Dumb8 CPU...\n"); cpu.pc = 0; cpu.halted = false; cpu.equal_flag = false; diff --git a/makefile b/makefile index 59003f9..e20ce02 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ all: - gcc -g *.c + gcc -g *.c -o dumb8 clean: rm a.out