diff options
| author | Julian Blake Kongslie | 2021-03-23 19:01:29 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-03-23 19:03:14 -0700 |
| commit | 0f95f3efbe4879bcf8b24aafda1c10dd95e9dd40 (patch) | |
| tree | b30ab627b29a881a2448bd28e6e02e4f8581ceba /ntoa.sv | |
| parent | Clean up the preshifts on bin2bcd and ntoa. (diff) | |
| download | toycpu-0f95f3efbe4879bcf8b24aafda1c10dd95e9dd40.tar.xz | |
Replace dibble dabble algorithm with variant that tests after the add.
This makes it really easy to support odd bases.
Diffstat (limited to 'ntoa.sv')
| -rw-r--r-- | ntoa.sv | 9 |
1 files changed, 5 insertions, 4 deletions
| @@ -1,5 +1,6 @@ | |||
| 1 | module ntoa | 1 | module ntoa |
| 2 | #( BITS = 8 | 2 | #( BITS = 8 |
| 3 | , BASE = 10 | ||
| 3 | ) | 4 | ) |
| 4 | ( input bit clk | 5 | ( input bit clk |
| 5 | , input bit reset | 6 | , input bit reset |
| @@ -19,7 +20,7 @@ bit [b2b.DIGITS-1:0][b2b.BASE_BITS-1:0] bcd_data; | |||
| 19 | 20 | ||
| 20 | bin2bcd | 21 | bin2bcd |
| 21 | #( .BITS(BITS) | 22 | #( .BITS(BITS) |
| 22 | , .BASE(10) | 23 | , .BASE(BASE) |
| 23 | ) b2b | 24 | ) b2b |
| 24 | ( .clk(clk) | 25 | ( .clk(clk) |
| 25 | , .reset(reset) | 26 | , .reset(reset) |
| @@ -50,10 +51,10 @@ always_ff @(posedge clk) begin | |||
| 50 | // verilator lint_off WIDTH | 51 | // verilator lint_off WIDTH |
| 51 | work = b2b.DIGITS; | 52 | work = b2b.DIGITS; |
| 52 | // verilator lint_on WIDTH | 53 | // verilator lint_on WIDTH |
| 53 | for (int i = 0; i < b2b.DIGITS - 1; i = i + 1) begin | 54 | for (int i = 0; i < b2b.DIGITS - 1; ++i) begin |
| 54 | if (bcd_b_data[b2b.DIGITS-1] != 0) break; | 55 | 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}} }; | 56 | bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; |
| 56 | work = work - 1; | 57 | --work; |
| 57 | end | 58 | end |
| 58 | end | 59 | end |
| 59 | 60 | ||
| @@ -68,7 +69,7 @@ always_ff @(posedge clk) begin | |||
| 68 | a_data = "a" + bcd_b_data[b2b.DIGITS-1] - 10; | 69 | a_data = "a" + bcd_b_data[b2b.DIGITS-1] - 10; |
| 69 | // verilator lint_off WIDTH | 70 | // verilator lint_off WIDTH |
| 70 | bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; | 71 | bcd_b_data = { bcd_b_data[b2b.DIGITS-2:0], {b2b.BASE_BITS{1'b0}} }; |
| 71 | work = work - 1; | 72 | --work; |
| 72 | end else begin | 73 | end else begin |
| 73 | a_valid = 1; | 74 | a_valid = 1; |
| 74 | a_data = ","; | 75 | a_data = ","; |
