summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-03-23 12:29:00 -0700
committerJulian Blake Kongslie2021-03-23 12:29:22 -0700
commited2f2d8e5df20768fd23c45d97478e19f7346725 (patch)
tree6e4a50dda735c23deb6d7a15c01ad2348c98ba88
parentInitial commit. (diff)
downloadtoycpu-ed2f2d8e5df20768fd23c45d97478e19f7346725.tar.xz
Clean up the preshifts on bin2bcd and ntoa.
Diffstat (limited to '')
-rw-r--r--bin2bcd.sv3
-rw-r--r--ntoa.sv2
2 files changed, 3 insertions, 2 deletions
diff --git a/bin2bcd.sv b/bin2bcd.sv
index 80dc633..266860c 100644
--- a/bin2bcd.sv
+++ b/bin2bcd.sv
@@ -1,6 +1,7 @@
1module bin2bcd 1module bin2bcd
2 #( BITS = 8 2 #( BITS = 8
3 , BASE = 10 3 , BASE = 10
4 , MAX_SKIP = BITS
4 ) 5 )
5 ( input bit clk 6 ( input bit clk
6 , input bit reset 7 , input bit reset
@@ -64,7 +65,7 @@ always_ff @(posedge clk) begin
64 bin_b_data = `bin_data; 65 bin_b_data = `bin_data;
65 bcd = 0; 66 bcd = 0;
66 work = BITS; 67 work = BITS;
67 for (int i = BITS; i > 0; i = i - 1) begin 68 for (int i = 0; i < BITS && i < MAX_SKIP; i = i + 1) begin
68 if (bin_b_data[BITS-1]) break; 69 if (bin_b_data[BITS-1]) break;
69 bin_b_data = { bin_b_data[BITS-2:0], 1'b0 }; 70 bin_b_data = { bin_b_data[BITS-2:0], 1'b0 };
70 work = work - 1; 71 work = work - 1;
diff --git a/ntoa.sv b/ntoa.sv
index c55c9e6..2a5c1ef 100644
--- a/ntoa.sv
+++ b/ntoa.sv
@@ -50,7 +50,7 @@ always_ff @(posedge clk) begin
50 // verilator lint_off WIDTH 50 // verilator lint_off WIDTH
51 work = b2b.DIGITS; 51 work = b2b.DIGITS;
52 // verilator lint_on WIDTH 52 // verilator lint_on WIDTH
53 for (int i = b2b.DIGITS; i > 1; i = i - 1) begin 53 for (int i = 0; i < b2b.DIGITS - 1; i = i + 1) begin
54 if (bcd_b_data[b2b.DIGITS-1] != 0) break; 54 if (bcd_b_data[b2b.DIGITS-1] != 0) break;
55 bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; 55 bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} };
56 work = work - 1; 56 work = work - 1;