diff options
| author | Julian Blake Kongslie | 2021-07-16 13:22:51 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-07-16 13:22:51 -0700 |
| commit | 765420c81d144bb08021a7aa09a9a0692f5d6322 (patch) | |
| tree | 757bee21385f646fe1fedb1eeba627acbb8cdd09 /sim | |
| parent | Reformat modules.rb to be a little easier to read. (diff) | |
| download | breadboarding-765420c81d144bb08021a7aa09a9a0692f5d6322.tar.xz | |
Add counter module and simplify board design for shift instructions.
Diffstat (limited to 'sim')
| -rw-r--r-- | sim/alu.sv | 4 | ||||
| -rw-r--r-- | sim/control.sv | 3 | ||||
| -rw-r--r-- | sim/counter.sv | 38 | ||||
| -rw-r--r-- | sim/top.sv | 1 |
4 files changed, 43 insertions, 3 deletions
| @@ -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}; |
| 52 | assign lshift_result = (dbus >= BUS_BITS) ? 0 : (abus << dbus); | 52 | assign lshift_result = {dbus[BUS_BITS-2:0], abus[0]}; |
| 53 | assign rshift_result = (dbus >= BUS_BITS) ? 0 : (abus >> dbus); | 53 | assign rshift_result = {abus[BUS_BITS-1], dbus[BUS_BITS-1:1]}; |
| 54 | 54 | ||
| 55 | bit [BUS_BITS-1:0] newx; | 55 | bit [BUS_BITS-1:0] newx; |
| 56 | assign newx = | 56 | assign 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}}; | |||
| 33 | assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}}; | 34 | assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}}; |
| 34 | 35 | ||
| 35 | bit cond; | 36 | bit cond; |
| 36 | assign cond = (dbus != 0) || ctrl[NOCOND]; | 37 | assign cond = ((dbus != 0) || ctrl[NOCOND]) ^ ctrl[ICOND]; |
| 37 | 38 | ||
| 38 | always @(posedge clk) begin | 39 | always @(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 @@ | |||
| 1 | module 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 | |||
| 14 | bit [BUS_BITS-1:0] x; | ||
| 15 | |||
| 16 | typedef enum | ||
| 17 | { LOAD | ||
| 18 | , INCREMENT | ||
| 19 | , DECREMENT | ||
| 20 | , OUTDATA | ||
| 21 | } CtrlBit; | ||
| 22 | |||
| 23 | bit [UROM_BITS-1:0] ctrl; | ||
| 24 | urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl); | ||
| 25 | |||
| 26 | assign dbus = ctrl[OUTDATA] ? x : {(BUS_BITS){1'bZ}}; | ||
| 27 | |||
| 28 | always @(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 | ||
| 36 | end | ||
| 37 | |||
| 38 | endmodule | ||
| @@ -14,6 +14,7 @@ bit [BUS_BITS-1:0] dbus; | |||
| 14 | 14 | ||
| 15 | alu #("../out/alu.bin", UIP_BITS, UROM_BITS, BUS_BITS) alu(clk, reset, uip, abus, dbus); | 15 | alu #("../out/alu.bin", UIP_BITS, UROM_BITS, BUS_BITS) alu(clk, reset, uip, abus, dbus); |
| 16 | control #("../out/control.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/consts.0.bin", "../out/consts.1.bin", 'h7ff8) control(clk, reset, uip, abus, dbus); | 16 | control #("../out/control.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/consts.0.bin", "../out/consts.1.bin", 'h7ff8) control(clk, reset, uip, abus, dbus); |
| 17 | counter #("../out/counter.bin", UIP_BITS, UROM_BITS, BUS_BITS) counter(clk, reset, uip, abus, dbus); | ||
| 17 | decode #("../out/decode.bin", UIP_BITS, UROM_BITS, BUS_BITS, 12) decode(clk, reset, uip, abus, dbus); | 18 | decode #("../out/decode.bin", UIP_BITS, UROM_BITS, BUS_BITS, 12) decode(clk, reset, uip, abus, dbus); |
| 18 | memory #("../out/memory.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/image.hex", MEM_BITS) memory(clk, reset, uip, abus, dbus); | 19 | memory #("../out/memory.bin", UIP_BITS, UROM_BITS, BUS_BITS, "../out/image.hex", MEM_BITS) memory(clk, reset, uip, abus, dbus); |
| 19 | pc #("../out/pc.bin", UIP_BITS, UROM_BITS, BUS_BITS, 0) pc(clk, reset, uip, abus, dbus); | 20 | pc #("../out/pc.bin", UIP_BITS, UROM_BITS, BUS_BITS, 0) pc(clk, reset, uip, abus, dbus); |
