Skip to content

Commit cf568fb

Browse files
Merge pull request #5 from scopeInfinity/pingpong
Ping Pong
2 parents f583d1e + 554fedf commit cf568fb

28 files changed

+1724
-348
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
sudo apt-get update
2525
sudo apt-get install iverilog
2626
- name: make test
27-
run: make test
27+
run: make clean && make test
2828
- name: make
2929
run: make all
3030
- name: Upload artifacts

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.vscode/
22
__pycache__/
33
build/
4-
output/

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ SRC_DIR=.
22
BUILD_DIR=build
33
OUTPUT_DIR=output
44

5-
.PHONY: clean test
5+
.PHONY: clean test all run_ping_pong all_programs_binary all_programs_resolved
6+
7+
all: all_programs_binary all_programs_resolved
68

79
clean:
8-
rm -r $(BUILD_DIR)
10+
rm -rf $(BUILD_DIR)
11+
rm -rf $(OUTPUT_DIR)
912

1013
include emulator/Makefile.mk
1114

1215
pytest:
13-
pytest -s --log-cli-level=DEBUG
16+
pytest -s --log-cli-level=INFO
1417

1518
test: pytest test_verilog_modules
1619

20+
all_programs_binary: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%.bin, $(shell find programs/ -name '*.asm'))
21+
1722
$(OUTPUT_DIR)/programs/%.bin: programs/%.asm
1823
mkdir -p $(dir $@)
1924
python3 -m planner asm -b $^ > $@
2025

26+
all_programs_resolved: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%_resolved.asm, $(shell find programs/ -name '*.asm'))
27+
28+
$(OUTPUT_DIR)/programs/%_resolved.asm: programs/%.asm
29+
mkdir -p $(dir $@)
30+
python3 -m planner asm -r $^ > $@
2131

22-
all: $(patsubst programs/%.asm, $(OUTPUT_DIR)/programs/%.bin, $(shell find programs/ -name '*.asm'))
32+
run_ping_pong:
33+
python3 -m planner compile_and_execute ping_pong

README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,18 @@
55

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

8-
## Verification
8+
## Sample Programs
99

10-
### Emulation
11-
12-
```
13-
# Build ROM[boot]
14-
$ python3 -rb assembler/assembler.py programs/boot_sequence.asm | tee build/boot_rom.txt.
15-
16-
# Write your program in custom assembly.
17-
$ cat programs/ping_pong.asm # we can proceeding with this
18-
19-
# Use assembler to translate the instructions into machine code.
20-
$ mkdir -p build
21-
$ python3 assembler/assembler.py -r programs/ping_pong.asm | tee build/ping_pong_resolved.txt # optional
22-
$ python3 assembler/assembler.py -rb programs/ping_pong.asm | tee build/ping_pong_rom.txt
23-
24-
# Use emulater the run the machine code.
25-
$ python3 emulator/emulate.py build/ping_pong_rom.txt
26-
```
10+
* Ping Pong
11+
* Source: [ping_pong.asm](programs/ping_pong.asm)
12+
* Generate resolved assembly: `python3 -m planner asm -r programs/ping_pong.asm` [[example](output/programs/ping_pong_resolved.asm)]
13+
* Generate binary: `python3 -m planner asm -b programs/ping_pong.asm` [[example](output/programs/ping_pong.bin)]
14+
* Run on emulator: `python3 -m planner compile_and_execute ping_pong`
2715

2816
## Design
2917

18+
This section is not up-to date.
19+
3020
### Specs
3121

3222
* Address Line: 16-bits

output/programs/3_led_switch.bin

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
00001100 01000010 00000001 00000001
2-
00000101 01001000 00000001 00000110
3-
00000001 11001111 00000000 00000000
4-
01000000
1+
00000000 00000000 00000000 00001100
2+
00100100 00000010 00000100 00000101
3+
00000100 00000100 00000110 00000100
4+
00110101 00001001 01000000 00000000
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PROGRAM_ORG equ 64
2+
040: IN [4], 5
3+
044: OUT 6, [4]
4+
048: JMP 64, 0

output/programs/boot_sequence.bin

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
00000000 00000000 00000000 00111100
2+
00110100 00000010 00000000 00000000
3+
00000100 00000100 00010000 00000000
4+
00100100 00000010 00000000 00000000
5+
00110100 00000010 00010100 00000000
6+
00110100 00000010 00000100 00000001
7+
00110100 00000010 00001000 01000000
8+
00000100 00000100 00010000 00000100
9+
00100100 00000010 00001100 00100000
10+
01000100 00000110 00001000 00001100
11+
01110000 00000010 00001000 00000100
12+
01110000 00000010 00000100 00000100
13+
01110001 00000010 00000000 00000100
14+
01000001 00000000 00000000 00010100
15+
00110101 00001011 01000000 00000000
16+
00110101 00001001 10011000 00000000
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
PROGRAM_ORG equ 128
2+
080: MOVC [0], 0
3+
084: OUT 16, [0]
4+
088: IN [0], 0
5+
08c: MOVC [20], 0
6+
090: MOVC [4], 1
7+
094: MOVC [8], 64
8+
098: OUT 16, [4]
9+
09c: IN [12], 32
10+
0a0: STORE [[8]], [12]
11+
0a4: ADDC [8], 4
12+
0a8: ADDC [4], 4
13+
0ac: SUBC [0], 4
14+
0b0: CMP [0], [20]
15+
0b4: JZ 64, 0
16+
0b8: JMP 152, 0

output/programs/ping_pong.bin

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
00000000 00000000 00000011 00110100
2+
00110100 00000010 00100000 11111111
3+
01110010 00000010 00100000 00001000
4+
01110111 00000010 00100000 11110000
5+
00110101 00001001 01110100 00000000
6+
00000010 00000000 00000000 00000000
7+
00000010 00000000 00000000 00000000
8+
00000111 00000000 00000000 00000000
9+
00000010 00000000 00000000 00000000
10+
11111111 11111111 00000000 00000000
11+
00000000 00000000 00000000 00000000
12+
00000110 00000000 00000000 00000000
13+
00000000 00000000 00000000 00000000
14+
00000001 00000000 00000000 00000000
15+
01110000 00000011 00101000 00010000
16+
01110001 00000010 00100000 00000100
17+
01000100 00000110 00100000 00101000
18+
00110101 00001001 01011100 00000001
19+
01110000 00000011 00101000 00010000
20+
01110001 00000010 00100000 00000100
21+
01000100 00000110 00100000 00101000
22+
00110101 00001001 11101100 00000000
23+
01110000 00000011 00101000 00010000
24+
01110001 00000010 00100000 00000100
25+
01000100 00000110 00100000 00101000
26+
00110101 00001001 00011100 00000010
27+
00110101 00001001 01110100 00000000
28+
01110000 00000011 00101000 00010000
29+
01110001 00000010 00100000 00000100
30+
01000100 00000110 00100000 00101000
31+
00110101 00001001 11001100 00000000
32+
01110000 00000011 00101000 00010000
33+
01110001 00000010 00100000 00000100
34+
01000100 00000110 00100000 00101000
35+
00110101 00001001 01011100 00000001
36+
00110101 00001001 10101000 00000000
37+
01110001 00000000 01101100 00000000
38+
00110101 00001101 11011100 00000000
39+
01111000 00000010 01110000 00000001
40+
00110100 00000010 01101100 00000101
41+
01110001 00000010 01101100 00000001
42+
10000101 00000010 00101000 00100000
43+
01110000 00000010 00100000 00000100
44+
11110101 00001000 00101000 00000000
45+
00100100 00000010 00000000 00000001
46+
00110100 00000010 00000100 00000001
47+
01000110 00000010 00000100 00000000
48+
00110101 00001011 00001000 00000001
49+
01110001 00000000 01010000 00000000
50+
00110101 00001011 00001000 00000001
51+
01110001 00000010 01010000 00000001
52+
00110100 00000010 00000100 00000010
53+
01000110 00000010 00000100 00000000
54+
00110101 00001011 00100000 00000001
55+
01110001 00000000 01010000 00000101
56+
00110101 00001011 00100000 00000001
57+
01110000 00000010 01010000 00000001
58+
00110100 00000010 00000100 00000100
59+
01000110 00000010 00000100 00000000
60+
00110101 00001011 00111000 00000001
61+
01110001 00000000 01010100 00000000
62+
00110101 00001011 00111000 00000001
63+
01110001 00000010 01010100 00000001
64+
00110100 00000010 00000100 00001000
65+
01000110 00000010 00000100 00000000
66+
00110101 00001011 01010000 00000001
67+
01110001 00000000 01010100 00000101
68+
00110101 00001011 01010000 00000001
69+
01110000 00000010 01010100 00000001
70+
10000101 00000010 00101000 00100000
71+
01110000 00000010 00100000 00000100
72+
11110101 00001000 00101000 00000000
73+
01110001 00000000 01110000 00000000
74+
00110101 00001011 10111100 00000001
75+
00110100 00000010 00000000 01111111
76+
01110010 00000010 00000000 00001000
77+
01111000 00000010 00000000 11111111
78+
00110100 00000010 00000100 00000111
79+
01000010 00000010 00000100 01010000
80+
00000100 00000100 00000110 00000000
81+
00000100 00000100 00000111 00000100
82+
01110000 00000011 00101000 00010000
83+
01110001 00000010 00100000 00000100
84+
01000100 00000110 00100000 00101000
85+
00110101 00001001 00000000 00000010
86+
00110100 00000010 00000000 11111111
87+
01110010 00000010 00000000 00001000
88+
01111000 00000010 00000000 11111110
89+
00110100 00000010 00000100 00000111
90+
01000010 00000010 00000100 01010100
91+
00000100 00000100 00000110 00000000
92+
00000100 00000100 00000111 00000100
93+
01110000 00000011 00101000 00010000
94+
01110001 00000010 00100000 00000100
95+
01000100 00000110 00100000 00101000
96+
00110101 00001001 00000000 00000010
97+
00000100 00000010 00000000 01011000
98+
00110100 00000010 00000100 10000000
99+
01110010 00000010 00000100 00001000
100+
01000011 00000010 00000100 00000000
101+
01001000 00000010 00000100 01100000
102+
00000100 00000010 00000000 01011100
103+
00110100 00000010 00001000 00000001
104+
01000010 00000010 00001000 00000000
105+
00000100 00000100 00000110 00000100
106+
00000100 00000100 00000111 00001000
107+
01110000 00000011 00101000 00010000
108+
01110001 00000010 00100000 00000100
109+
01000100 00000110 00100000 00101000
110+
00110101 00001001 00000000 00000010
111+
10000101 00000010 00101000 00100000
112+
01110000 00000010 00100000 00000100
113+
11110101 00001000 00101000 00000000
114+
00110100 00000010 00000000 11110000
115+
01110010 00000010 00000000 00000001
116+
01110001 00000010 00000000 00000001
117+
00110101 00001101 00001000 00000010
118+
10000101 00000010 00101000 00100000
119+
01110000 00000010 00100000 00000100
120+
11110101 00001000 00101000 00000000
121+
01110001 00000000 01100100 00000000
122+
00110101 00001101 00111000 00000010
123+
00110100 00000010 01100100 00000010
124+
01110000 00000011 00101000 00010000
125+
01110001 00000010 00100000 00000100
126+
01000100 00000110 00100000 00101000
127+
00110101 00001001 01001000 00000010
128+
01110001 00000010 01100100 00000001
129+
10000101 00000010 00101000 00100000
130+
01110000 00000010 00100000 00000100
131+
11110101 00001000 00101000 00000000
132+
01110001 00000000 01011000 00001110
133+
00110101 00001011 10101100 00000010
134+
01110001 00000000 01011000 00000001
135+
00110101 00001011 11010000 00000010
136+
01110001 00000000 01011100 00000111
137+
00110101 00001011 01100000 00000011
138+
01110001 00000000 01011100 00000000
139+
00110101 00001011 01100000 00000011
140+
00000100 00000010 00000000 01101000
141+
01110110 00000010 00000000 00000001
142+
00110101 00001011 01111100 00000010
143+
01110000 00000010 01011000 00000001
144+
00110101 00001001 10000000 00000010
145+
01110001 00000010 01011000 00000001
146+
00000100 00000010 00000000 01101000
147+
01110110 00000010 00000000 00000100
148+
00110101 00001011 10010000 00000010
149+
01110001 00000010 01011100 00000001
150+
00000100 00000010 00000000 01101000
151+
01110110 00000010 00000000 00001000
152+
00110101 00001011 10100000 00000010
153+
01110000 00000010 01011100 00000001
154+
10000101 00000010 00101000 00100000
155+
01110000 00000010 00100000 00000100
156+
11110101 00001000 00101000 00000000
157+
01110001 00000010 00100000 00000100
158+
01000100 00000110 00100000 01010100
159+
01110000 00000011 00101000 00010000
160+
01110001 00000010 00100000 00000100
161+
01000100 00000110 00100000 00101000
162+
00110101 00001001 11110100 00000010
163+
10000101 00000010 00011100 00100000
164+
01110000 00000010 00100000 00000100
165+
00110101 00001001 01011000 00000010
166+
01110001 00000010 00100000 00000100
167+
01000100 00000110 00100000 01010000
168+
01110000 00000011 00101000 00010000
169+
01110001 00000010 00100000 00000100
170+
01000100 00000110 00100000 00101000
171+
00110101 00001001 11110100 00000010
172+
10000101 00000010 00011100 00100000
173+
01110000 00000010 00100000 00000100
174+
00110101 00001001 01011000 00000010
175+
00000100 00000010 00100100 00100000
176+
01110000 00000010 00100100 00000100
177+
10000101 00000010 00000100 00100100
178+
01111000 00000010 01101000 00000011
179+
00110100 00000010 00000000 00001100
180+
01111000 00000010 00000000 11111111
181+
01000110 00000010 01101000 00000000
182+
01000001 00000000 01011100 00000100
183+
00110101 00001011 00110100 00000011
184+
01110000 00000010 00000100 00000001
185+
01000001 00000000 01011100 00000100
186+
00110101 00001011 01010100 00000011
187+
01110000 00000010 00000100 00000001
188+
01000001 00000000 01011100 00000100
189+
00110101 00001011 01000100 00000011
190+
00110101 00001001 10101000 00000000
191+
01110111 00000010 01101000 00000100
192+
10000101 00000010 00101000 00100000
193+
01110000 00000010 00100000 00000100
194+
11110101 00001000 00101000 00000000
195+
01110111 00000010 01101000 00001000
196+
10000101 00000010 00101000 00100000
197+
01110000 00000010 00100000 00000100
198+
11110101 00001000 00101000 00000000
199+
10000101 00000010 00101000 00100000
200+
01110000 00000010 00100000 00000100
201+
11110101 00001000 00101000 00000000
202+
00000100 00000010 00000000 01101000
203+
01110110 00000010 00000000 00001100
204+
00110101 00001011 01101000 00000010
205+
01111000 00000010 01101000 00001100
206+
00110101 00001001 01101000 00000010

0 commit comments

Comments
 (0)