Skip to content

Commit 49165de

Browse files
committed
Change instruction binary to contain the ALU mode
1 parent 015a262 commit 49165de

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

asm/asm.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44

55
progf = sys.argv[1]
66

7-
inst = ["nop", "lda", "add", "out", "jmp", "hlt", "sub", "jez", "sta", "jnz"]
7+
inst = {
8+
"nop": 0x00,
9+
"lda": 0x01,
10+
"out": 0x03,
11+
"jmp": 0x04,
12+
"hlt": 0x05,
13+
"jez": 0x07,
14+
"sta": 0x08,
15+
"jnz": 0x09,
16+
"add": 0xa0,
17+
"sub": 0xa1,
18+
}
819

920
PROGRAM, DATA = 0, 1
1021
MEM_SIZE = 256
@@ -35,7 +46,7 @@
3546
if kw[0][-1] == ":":
3647
labels[kw[0].rstrip(":")] = cnt
3748
else:
38-
mem[cnt] = inst.index(kw[0])
49+
mem[cnt] = inst[kw[0]]
3950
cnt += 1
4051
for a in kw[1:]:
4152
mem[cnt] = a

gtkwave/config.gtkw

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[*]
22
[*] GTKWave Analyzer v3.3.66 (w)1999-2015 BSI
3-
[*] Wed Aug 30 06:16:21 2017
3+
[*] Thu Aug 31 05:57:26 2017
44
[*]
55
[dumpfile] "machine.vcd"
6-
[dumpfile_mtime] "Wed Aug 30 05:25:30 2017"
7-
[dumpfile_size] 52264
8-
[savefile] "config.gtkw"
9-
[timestart] 0
6+
[dumpfile_mtime] "Wed Aug 30 17:33:50 2017"
7+
[dumpfile_size] 53507
8+
[savefile] "gtkwave/config.gtkw"
9+
[timestart] 1102
1010
[size] 1916 1042
1111
[pos] -960 39
12-
*-3.000000 30 170 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
12+
*-3.000000 1120 170 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
1313
[treeopen] machine_tb.
1414
[treeopen] machine_tb.m_machine.
1515
[sst_width] 223
@@ -30,12 +30,9 @@ machine_tb.m_machine.m_cpu.internal_clk
3030
@28
3131
machine_tb.m_machine.m_cpu.reset
3232
@2022
33-
^2 gtkwave/states.txt
33+
^1 gtkwave/states.txt
3434
machine_tb.m_machine.m_cpu.state[3:0]
35-
@28
36-
machine_tb.m_machine.m_cpu.cycle_clk
37-
@2022
38-
^1 gtkwave/opcode.txt
35+
^2 gtkwave/opcode.txt
3936
machine_tb.m_machine.m_cpu.opcode[7:0]
4037
@1000200
4138
-Control

gtkwave/opcode.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
00 NOP
22
01 LDA
3-
02 ADD
43
03 OUT
54
04 JMP
65
05 HLT
7-
06 SUB
86
07 JEZ
97
08 STA
108
09 JNZ
9+
A0 ADD
10+
A1 SUB

rtl/cpu.v

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ module cpu(
150150
assign jump_allowed = opcode == `OP_JMP | (opcode == `OP_JEZ & eq_zero) | (opcode == `OP_JNZ & !eq_zero);
151151

152152
assign c_next = state == `STATE_NEXT | reset;
153-
assign alu_mode = (opcode == `OP_SUB) ? `ALU_SUB :
154-
(opcode == `OP_ADD) ? `ALU_ADD :
155-
'bx;
153+
assign alu_mode = (state == `STATE_ALU_OP) ? opcode[3:0] : 'bx;
156154

157155
assign c_ai = state == `STATE_RAM_A | state == `STATE_ALU_OP;
158156
assign c_ao = state == `STATE_OUT_A | state == `STATE_STORE_A;

rtl/parameters.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
`define OP_NOP 8'h00
22
`define OP_LDA 8'h01
3-
`define OP_ADD 8'h02
43
`define OP_OUT 8'h03
54
`define OP_JMP 8'h04
65
`define OP_HLT 8'h05
7-
`define OP_SUB 8'h06
86
`define OP_JEZ 8'h07
97
`define OP_STA 8'h08
108
`define OP_JNZ 8'h09
9+
`define OP_ADD 8'ha0
10+
`define OP_SUB 8'ha1
1111

1212
`define STATE_NEXT 4'h0
1313
`define STATE_FETCH_PC 4'h1

0 commit comments

Comments
 (0)