summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/alu.sv4
-rw-r--r--sim/control.sv3
-rw-r--r--sim/counter.sv38
-rw-r--r--sim/top.sv1
4 files changed, 43 insertions, 3 deletions
diff --git a/sim/alu.sv b/sim/alu.sv
index 407b083..5583492 100644
--- a/sim/alu.sv
+++ b/sim/alu.sv
@@ -49,8 +49,8 @@ assign cmp_result = {{(BUS_BITS-6){1'b0}},
49 abus > dbus, 49 abus > dbus,
50 abus == dbus, 50 abus == dbus,
51 abus < dbus}; 51 abus < dbus};
52assign lshift_result = (dbus >= BUS_BITS) ? 0 : (abus << dbus); 52assign lshift_result = {dbus[BUS_BITS-2:0], abus[0]};
53assign rshift_result = (dbus >= BUS_BITS) ? 0 : (abus >> dbus); 53assign rshift_result = {abus[BUS_BITS-1], dbus[BUS_BITS-1:1]};
54 54
55bit [BUS_BITS-1:0] newx; 55bit [BUS_BITS-1:0] newx;
56assign newx = 56assign newx =
diff --git a/sim/control.sv b/sim/control.sv
index 7808f61..ddd6401 100644
--- a/sim/control.sv
+++ b/sim/control.sv
@@ -18,6 +18,7 @@ typedef enum
18 { HALT 18 { HALT
19 , SET_UIP_COND 19 , SET_UIP_COND
20 , NOCOND 20 , NOCOND
21 , ICOND
21 , OUTADDR 22 , OUTADDR
22 , OUTDATA 23 , OUTDATA
23 } CtrlBit; 24 } CtrlBit;
@@ -33,7 +34,7 @@ assign abus = ctrl[OUTADDR] ? constant : {(BUS_BITS){1'bZ}};
33assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}}; 34assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}};
34 35
35bit cond; 36bit cond;
36assign cond = (dbus != 0) || ctrl[NOCOND]; 37assign cond = ((dbus != 0) || ctrl[NOCOND]) ^ ctrl[ICOND];
37 38
38always @(posedge clk) begin 39always @(posedge clk) begin
39 if (reset) begin 40 if (reset) begin
diff --git a/sim/counter.sv b/sim/counter.sv
new file mode 100644
index 0000000..1316783
--- /dev/null
+++ b/sim/counter.sv
@@ -0,0 +1,38 @@
1module counter
2 #( parameter UROM = "<no file specified>"
3 , parameter UIP_BITS = 15
4 , parameter UROM_BITS = 8
5 , parameter BUS_BITS = 16
6 )
7 ( input bit clk
8 , input bit reset
9 , input bit [UIP_BITS-1:0] uip
10 , inout bit [BUS_BITS-1:0] abus
11 , inout bit [BUS_BITS-1:0] dbus
12 );
13
14bit [BUS_BITS-1:0] x;
15
16typedef enum
17 { LOAD
18 , INCREMENT
19 , DECREMENT
20 , OUTDATA
21 } CtrlBit;
22
23bit [UROM_BITS-1:0] ctrl;
24urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl);
25
26assign dbus = ctrl[OUTDATA] ? x : {(BUS_BITS){1'bZ}};
27
28always @(posedge clk) begin
29 if (ctrl[LOAD]) begin
30 x <= dbus;
31 end else if (ctrl[INCREMENT]) begin
32 x <= x + 1;
33 end else if (ctrl[DECREMENT]) begin
34 x <= x - 1;
35 end
36end
37
38endmodule
diff --git a/sim/top.sv b/sim/top.sv
index 6773739..464b93d 100644
--- a/sim/top.sv
+++ b/sim/top.sv
@@ -14,6 +14,7 @@ bit [BUS_BITS-1:0] dbus;
14 14
15alu #("../out/alu.bin", UIP_BITS, UROM_BITS, BUS_BITS) alu(clk, reset, uip, abus, dbus); 15alu #("../out/alu.bin", UIP_BITS, UROM_BITS, BUS_BITS) alu(clk, reset, uip, abus, dbus);
16control #("../out/control.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/consts.0.bin", "../out/consts.1.bin", 'h7ff8) control(clk, reset, uip, abus, dbus); 16control #("../out/control.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/consts.0.bin", "../out/consts.1.bin", 'h7ff8) control(clk, reset, uip, abus, dbus);
17counter #("../out/counter.bin", UIP_BITS, UROM_BITS, BUS_BITS) counter(clk, reset, uip, abus, dbus);
17decode #("../out/decode.bin", UIP_BITS, UROM_BITS, BUS_BITS, 12) decode(clk, reset, uip, abus, dbus); 18decode #("../out/decode.bin", UIP_BITS, UROM_BITS, BUS_BITS, 12) decode(clk, reset, uip, abus, dbus);
18memory #("../out/memory.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/image.hex", MEM_BITS) memory(clk, reset, uip, abus, dbus); 19memory #("../out/memory.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/image.hex", MEM_BITS) memory(clk, reset, uip, abus, dbus);
19pc #("../out/pc.bin", UIP_BITS, UROM_BITS, BUS_BITS, 0) pc(clk, reset, uip, abus, dbus); 20pc #("../out/pc.bin", UIP_BITS, UROM_BITS, BUS_BITS, 0) pc(clk, reset, uip, abus, dbus);