Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 1ps
- //////////////////////////////////////////////////////////////////////////////////
- // Company: Universidad Autonoma Metropolitana Unidad Azcapotzalco
- // Engineer: Angel Guerra Esquivel
- //
- // Create Date: 19:20:38 05/09/2022
- // Design Name:
- // Module Name: DoubleDabble
- // Project Name: ALU
- // Target Devices: Nexys4
- // Tool versions:
- // Description:
- //
- // Dependencies:
- //
- // Revision:
- // Revision 0.01 - File Created
- // Additional Comments:
- //
- //////////////////////////////////////////////////////////////////////////////////
- module DoubleDabble
- #( parameter BITS = 12) // input width
- ( input [BITS-1:0] bin , // binary
- output reg [15:0] bcd );
- reg [3:0] i;
- always @(bin)
- begin
- bcd = 0; // inicializando el registro bcd a ceros.
- for (i = 0; i < BITS; i = i+1) // # de iteraciones = al # de BITS
- begin
- bcd = {bcd[14:0],bin[(BITS-1)-i]}; //realiza el corrimiento descartando el ultimo bit de bcd concatenando con bin de derecha a izq
- //DoubleDabble, alguna de las partes es >= a 5, suma 3
- if(i < (BITS-1) && bcd[3:0] >= 5) //unidades
- bcd[3:0] = bcd[3:0] + 3;
- if(i < (BITS-1) && bcd[7:4] >= 5) //decenas
- bcd[7:4] = bcd[7:4] + 3;
- if(i < (BITS-1) && bcd[11:8] >= 5)//centenas
- bcd[11:8] = bcd[11:8] + 3;
- if(i < (BITS-1) && bcd[15:12] >= 5)//millares
- bcd[15:12] = bcd[15:12] + 3;
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment