From 0f95f3efbe4879bcf8b24aafda1c10dd95e9dd40 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Tue, 23 Mar 2021 19:01:29 -0700 Subject: Replace dibble dabble algorithm with variant that tests after the add. This makes it really easy to support odd bases. --- ntoa.sv | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ntoa.sv') diff --git a/ntoa.sv b/ntoa.sv index 2a5c1ef..f8e9f43 100644 --- a/ntoa.sv +++ b/ntoa.sv @@ -1,5 +1,6 @@ module ntoa #( BITS = 8 + , BASE = 10 ) ( input bit clk , input bit reset @@ -19,7 +20,7 @@ bit [b2b.DIGITS-1:0][b2b.BASE_BITS-1:0] bcd_data; bin2bcd #( .BITS(BITS) - , .BASE(10) + , .BASE(BASE) ) b2b ( .clk(clk) , .reset(reset) @@ -50,10 +51,10 @@ always_ff @(posedge clk) begin // verilator lint_off WIDTH work = b2b.DIGITS; // verilator lint_on WIDTH - for (int i = 0; i < b2b.DIGITS - 1; i = i + 1) begin + for (int i = 0; i < b2b.DIGITS - 1; ++i) begin if (bcd_b_data[b2b.DIGITS-1] != 0) break; bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; - work = work - 1; + --work; end end @@ -68,7 +69,7 @@ always_ff @(posedge clk) begin a_data = "a" + bcd_b_data[b2b.DIGITS-1] - 10; // verilator lint_off WIDTH bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; - work = work - 1; + --work; end else begin a_valid = 1; a_data = ","; -- cgit v1.2.3