Skip to content

Ping Pong #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
sudo apt-get update
sudo apt-get install iverilog
- name: make test
run: make test
run: make clean && make test
- name: make
run: make all
- name: Upload artifacts
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.vscode/
__pycache__/
build/
output/
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ SRC_DIR=.
BUILD_DIR=build
OUTPUT_DIR=output

.PHONY: clean test
.PHONY: clean test all run_ping_pong all_programs_binary all_programs_resolved

all: all_programs_binary all_programs_resolved

clean:
rm -r $(BUILD_DIR)
rm -rf $(BUILD_DIR)
rm -rf $(OUTPUT_DIR)

include emulator/Makefile.mk

pytest:
pytest -s --log-cli-level=DEBUG
pytest -s --log-cli-level=INFO

test: pytest test_verilog_modules

all_programs_binary: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%.bin, $(shell find programs/ -name '*.asm'))

$(OUTPUT_DIR)/programs/%.bin: programs/%.asm
mkdir -p $(dir $@)
python3 -m planner asm -b $^ > $@

all_programs_resolved: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%_resolved.asm, $(shell find programs/ -name '*.asm'))

$(OUTPUT_DIR)/programs/%_resolved.asm: programs/%.asm
mkdir -p $(dir $@)
python3 -m planner asm -r $^ > $@

all: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%.bin, $(shell find programs/ -name '*.asm'))
run_ping_pong:
python3 -m planner compile_and_execute ping_pong
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@

The eventual goal(?) is to build a general-purpose processor integrated with simple input (e.g. buttons) and output devices (8x8 LED display).

## Verification
## Sample Programs

### Emulation

```
# Build ROM[boot]
$ python3 -rb assembler/assembler.py programs/boot_sequence.asm | tee build/boot_rom.txt.

# Write your program in custom assembly.
$ cat programs/ping_pong.asm # we can proceeding with this

# Use assembler to translate the instructions into machine code.
$ mkdir -p build
$ python3 assembler/assembler.py -r programs/ping_pong.asm | tee build/ping_pong_resolved.txt # optional
$ python3 assembler/assembler.py -rb programs/ping_pong.asm | tee build/ping_pong_rom.txt

# Use emulater the run the machine code.
$ python3 emulator/emulate.py build/ping_pong_rom.txt
```
* Ping Pong
* Source: [ping_pong.asm](programs/ping_pong.asm)
* Generate resolved assembly: `python3 -m planner asm -r programs/ping_pong.asm` [[example](output/programs/ping_pong_resolved.asm)]
* Generate binary: `python3 -m planner asm -b programs/ping_pong.asm` [[example](output/programs/ping_pong.bin)]
* Run on emulator: `python3 -m planner compile_and_execute ping_pong`

## Design

This section is not up-to date.

### Specs

* Address Line: 16-bits
Expand Down
8 changes: 4 additions & 4 deletions output/programs/3_led_switch.bin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
00001100 01000010 00000001 00000001
00000101 01001000 00000001 00000110
00000001 11001111 00000000 00000000
01000000
00000000 00000000 00000000 00001100
00100100 00000010 00000100 00000101
00000100 00000100 00000110 00000100
00110101 00001001 01000000 00000000
4 changes: 4 additions & 0 deletions output/programs/3_led_switch_resolved.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROGRAM_ORG equ 64
040: IN [4], 5
044: OUT 6, [4]
048: JMP 64, 0
16 changes: 16 additions & 0 deletions output/programs/boot_sequence.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
00000000 00000000 00000000 00111100
00110100 00000010 00000000 00000000
00000100 00000100 00010000 00000000
00100100 00000010 00000000 00000000
00110100 00000010 00010100 00000000
00110100 00000010 00000100 00000001
00110100 00000010 00001000 01000000
00000100 00000100 00010000 00000100
00100100 00000010 00001100 00100000
01000100 00000110 00001000 00001100
01110000 00000010 00001000 00000100
01110000 00000010 00000100 00000100
01110001 00000010 00000000 00000100
01000001 00000000 00000000 00010100
00110101 00001011 01000000 00000000
00110101 00001001 10011000 00000000
16 changes: 16 additions & 0 deletions output/programs/boot_sequence_resolved.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROGRAM_ORG equ 128
080: MOVC [0], 0
084: OUT 16, [0]
088: IN [0], 0
08c: MOVC [20], 0
090: MOVC [4], 1
094: MOVC [8], 64
098: OUT 16, [4]
09c: IN [12], 32
0a0: STORE [[8]], [12]
0a4: ADDC [8], 4
0a8: ADDC [4], 4
0ac: SUBC [0], 4
0b0: CMP [0], [20]
0b4: JZ 64, 0
0b8: JMP 152, 0
206 changes: 206 additions & 0 deletions output/programs/ping_pong.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
00000000 00000000 00000011 00110100
00110100 00000010 00100000 11111111
01110010 00000010 00100000 00001000
01110111 00000010 00100000 11110000
00110101 00001001 01110100 00000000
00000010 00000000 00000000 00000000
00000010 00000000 00000000 00000000
00000111 00000000 00000000 00000000
00000010 00000000 00000000 00000000
11111111 11111111 00000000 00000000
00000000 00000000 00000000 00000000
00000110 00000000 00000000 00000000
00000000 00000000 00000000 00000000
00000001 00000000 00000000 00000000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 01011100 00000001
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 11101100 00000000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 00011100 00000010
00110101 00001001 01110100 00000000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 11001100 00000000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 01011100 00000001
00110101 00001001 10101000 00000000
01110001 00000000 01101100 00000000
00110101 00001101 11011100 00000000
01111000 00000010 01110000 00000001
00110100 00000010 01101100 00000101
01110001 00000010 01101100 00000001
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
00100100 00000010 00000000 00000001
00110100 00000010 00000100 00000001
01000110 00000010 00000100 00000000
00110101 00001011 00001000 00000001
01110001 00000000 01010000 00000000
00110101 00001011 00001000 00000001
01110001 00000010 01010000 00000001
00110100 00000010 00000100 00000010
01000110 00000010 00000100 00000000
00110101 00001011 00100000 00000001
01110001 00000000 01010000 00000101
00110101 00001011 00100000 00000001
01110000 00000010 01010000 00000001
00110100 00000010 00000100 00000100
01000110 00000010 00000100 00000000
00110101 00001011 00111000 00000001
01110001 00000000 01010100 00000000
00110101 00001011 00111000 00000001
01110001 00000010 01010100 00000001
00110100 00000010 00000100 00001000
01000110 00000010 00000100 00000000
00110101 00001011 01010000 00000001
01110001 00000000 01010100 00000101
00110101 00001011 01010000 00000001
01110000 00000010 01010100 00000001
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
01110001 00000000 01110000 00000000
00110101 00001011 10111100 00000001
00110100 00000010 00000000 01111111
01110010 00000010 00000000 00001000
01111000 00000010 00000000 11111111
00110100 00000010 00000100 00000111
01000010 00000010 00000100 01010000
00000100 00000100 00000110 00000000
00000100 00000100 00000111 00000100
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 00000000 00000010
00110100 00000010 00000000 11111111
01110010 00000010 00000000 00001000
01111000 00000010 00000000 11111110
00110100 00000010 00000100 00000111
01000010 00000010 00000100 01010100
00000100 00000100 00000110 00000000
00000100 00000100 00000111 00000100
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 00000000 00000010
00000100 00000010 00000000 01011000
00110100 00000010 00000100 10000000
01110010 00000010 00000100 00001000
01000011 00000010 00000100 00000000
01001000 00000010 00000100 01100000
00000100 00000010 00000000 01011100
00110100 00000010 00001000 00000001
01000010 00000010 00001000 00000000
00000100 00000100 00000110 00000100
00000100 00000100 00000111 00001000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 00000000 00000010
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
00110100 00000010 00000000 11110000
01110010 00000010 00000000 00000001
01110001 00000010 00000000 00000001
00110101 00001101 00001000 00000010
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
01110001 00000000 01100100 00000000
00110101 00001101 00111000 00000010
00110100 00000010 01100100 00000010
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 01001000 00000010
01110001 00000010 01100100 00000001
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
01110001 00000000 01011000 00001110
00110101 00001011 10101100 00000010
01110001 00000000 01011000 00000001
00110101 00001011 11010000 00000010
01110001 00000000 01011100 00000111
00110101 00001011 01100000 00000011
01110001 00000000 01011100 00000000
00110101 00001011 01100000 00000011
00000100 00000010 00000000 01101000
01110110 00000010 00000000 00000001
00110101 00001011 01111100 00000010
01110000 00000010 01011000 00000001
00110101 00001001 10000000 00000010
01110001 00000010 01011000 00000001
00000100 00000010 00000000 01101000
01110110 00000010 00000000 00000100
00110101 00001011 10010000 00000010
01110001 00000010 01011100 00000001
00000100 00000010 00000000 01101000
01110110 00000010 00000000 00001000
00110101 00001011 10100000 00000010
01110000 00000010 01011100 00000001
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 01010100
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 11110100 00000010
10000101 00000010 00011100 00100000
01110000 00000010 00100000 00000100
00110101 00001001 01011000 00000010
01110001 00000010 00100000 00000100
01000100 00000110 00100000 01010000
01110000 00000011 00101000 00010000
01110001 00000010 00100000 00000100
01000100 00000110 00100000 00101000
00110101 00001001 11110100 00000010
10000101 00000010 00011100 00100000
01110000 00000010 00100000 00000100
00110101 00001001 01011000 00000010
00000100 00000010 00100100 00100000
01110000 00000010 00100100 00000100
10000101 00000010 00000100 00100100
01111000 00000010 01101000 00000011
00110100 00000010 00000000 00001100
01111000 00000010 00000000 11111111
01000110 00000010 01101000 00000000
01000001 00000000 01011100 00000100
00110101 00001011 00110100 00000011
01110000 00000010 00000100 00000001
01000001 00000000 01011100 00000100
00110101 00001011 01010100 00000011
01110000 00000010 00000100 00000001
01000001 00000000 01011100 00000100
00110101 00001011 01000100 00000011
00110101 00001001 10101000 00000000
01110111 00000010 01101000 00000100
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
01110111 00000010 01101000 00001000
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
10000101 00000010 00101000 00100000
01110000 00000010 00100000 00000100
11110101 00001000 00101000 00000000
00000100 00000010 00000000 01101000
01110110 00000010 00000000 00001100
00110101 00001011 01101000 00000010
01111000 00000010 01101000 00001100
00110101 00001001 01101000 00000010
Loading
Loading