bin_to_dec.v
来自「本電子檔為 verilog cookbook,包含了通訊,影像,DSP等重要常用」· Verilog 代码 · 共 252 行 · 第 1/2 页
V
252 行
// Copyright 2007 Altera Corporation. All rights reserved.
// Altera products are protected under numerous U.S. and foreign patents,
// maskwork rights, copyrights and other intellectual property laws.
//
// This reference design file, and your use thereof, is subject to and governed
// by the terms and conditions of the applicable Altera Reference Design
// License Agreement (either as signed by you or found at www.altera.com). By
// using this reference design file, you indicate your acceptance of such terms
// and conditions between you and Altera Corporation. In the event that you do
// not agree with such terms and conditions, you may not use the reference
// design file and please promptly destroy any copies you have made.
//
// This reference design file is being provided on an "as-is" basis and as an
// accommodation and therefore all warranties, representations or guarantees of
// any kind (whether express, implied or statutory) including, without
// limitation, warranties of merchantability, non-infringement, or fitness for
// a particular purpose, are specifically disclaimed. By making this reference
// design file available, Altera expressly does not recommend, suggest or
// require that this reference design file be used in combination with any
// other product not provided by Altera.
/////////////////////////////////////////////////////////////////////////////
// baeckler - 08-29-2006
// 32 bit binary to binary coded decimal (BCD)
module bin_to_dec (ins,out);
input [31:0] ins;
output [10*4-1:0] out;
// dispose of powers 1 and 2 in the low bits of the next three compressors
// - the odd / even of the sum is only controlled by bit 0, so the lowest
// bit is gnd when un-tampered
// powers : 4 8 16 32 64 128
wire [63:0] p2_dig_0_bit_0 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p2_dig_0_bit_1 = 64'b1000110001100011000110001100011000110001100011000110001100011000;
wire [63:0] p2_dig_0_bit_2 = 64'b0010100101001010010100101001010010100101001010010100101001010010;
wire [63:0] p2_dig_0_bit_3 = 64'b0100001000010000100001000010000100001000010000100001000010000100;
wire [63:0] p2_dig_1_bit_0 = 64'b1000110001100011000110001100011000110001100011000110001100011000;
wire [63:0] p2_dig_1_bit_1 = 64'b0000111110000000000111110000011111000000000011111000001111100000;
wire [63:0] p2_dig_1_bit_2 = 64'b1111000000000000000111111111100000000000000011111111110000000000;
wire [63:0] p2_dig_1_bit_3 = 64'b0000000000000011111000000000000000000001111100000000000000000000;
wire [63:0] p2_dig_2_bit_0 = 64'b0000000000000011111111111111111111111110000000000000000000000000;
wire [63:0] p2_dig_2_bit_1 = 64'b1111111111111100000000000000000000000000000000000000000000000000;
wire [63:0] p2_dig_2_bit_2 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p2_dig_2_bit_3 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [5:0] p2_ins = {ins[7],ins[6],ins[5],ins[4],ins[3],ins[2]};
wire [11:0] p2_outs = {
p2_dig_2_bit_3[p2_ins],p2_dig_2_bit_2[p2_ins],p2_dig_2_bit_1[p2_ins],p2_dig_2_bit_0[p2_ins],
p2_dig_1_bit_3[p2_ins],p2_dig_1_bit_2[p2_ins],p2_dig_1_bit_1[p2_ins],p2_dig_1_bit_0[p2_ins],
p2_dig_0_bit_3[p2_ins],p2_dig_0_bit_2[p2_ins],p2_dig_0_bit_1[p2_ins],ins[0]
};
// powers : 256 512 1024 2048 4096 8192
wire [63:0] p8_dig_0_bit_0 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p8_dig_0_bit_1 = 64'b0110001100011000110001100011000110001100011000110001100011000110;
wire [63:0] p8_dig_0_bit_2 = 64'b0010100101001010010100101001010010100101001010010100101001010010;
wire [63:0] p8_dig_0_bit_3 = 64'b1000010000100001000010000100001000010000100001000010000100001000;
wire [63:0] p8_dig_1_bit_0 = 64'b0110001100011000110001100011000110001100011000110001100011000110;
wire [63:0] p8_dig_1_bit_1 = 64'b1101000101100000111100000110100010110000011110000011010001011000;
wire [63:0] p8_dig_1_bit_2 = 64'b0101010000101010010101010010101000010101001010101001010100001010;
wire [63:0] p8_dig_1_bit_3 = 64'b0000001010000001000000101000000101000000100000010100000010100000;
wire [63:0] p8_dig_2_bit_0 = 64'b1001101100110010011001001100110110011001001100100110011011001100;
wire [63:0] p8_dig_2_bit_1 = 64'b0011000100010001010101010101010001000100011001100010001010101010;
wire [63:0] p8_dig_2_bit_2 = 64'b0010001000100010011001100110011001100110010001000100010011001100;
wire [63:0] p8_dig_2_bit_3 = 64'b0100010001000100000000001000100010001000100010001000100000000000;
wire [63:0] p8_dig_3_bit_0 = 64'b0111100001111000011110001111000011110000111100001111000011110000;
wire [63:0] p8_dig_3_bit_1 = 64'b1000000001111111100000000000000011111111000000001111111100000000;
wire [63:0] p8_dig_3_bit_2 = 64'b1111111110000000000000000000000011111111111111110000000000000000;
wire [63:0] p8_dig_3_bit_3 = 64'b0000000000000000000000001111111100000000000000000000000000000000;
wire [63:0] p8_dig_4_bit_0 = 64'b1111111111111111111111110000000000000000000000000000000000000000;
wire [63:0] p8_dig_4_bit_1 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p8_dig_4_bit_2 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p8_dig_4_bit_3 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [5:0] p8_ins = {ins[13],ins[12],ins[11],ins[10],ins[9],ins[8]};
wire [19:0] p8_outs = {
p8_dig_4_bit_3[p8_ins],p8_dig_4_bit_2[p8_ins],p8_dig_4_bit_1[p8_ins],p8_dig_4_bit_0[p8_ins],
p8_dig_3_bit_3[p8_ins],p8_dig_3_bit_2[p8_ins],p8_dig_3_bit_1[p8_ins],p8_dig_3_bit_0[p8_ins],
p8_dig_2_bit_3[p8_ins],p8_dig_2_bit_2[p8_ins],p8_dig_2_bit_1[p8_ins],p8_dig_2_bit_0[p8_ins],
p8_dig_1_bit_3[p8_ins],p8_dig_1_bit_2[p8_ins],p8_dig_1_bit_1[p8_ins],p8_dig_1_bit_0[p8_ins],
p8_dig_0_bit_3[p8_ins],p8_dig_0_bit_2[p8_ins],p8_dig_0_bit_1[p8_ins],ins[1]
};
// powers : 16384 32768 65536 131072 262144 524288
wire [63:0] p14_dig_0_bit_0 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p14_dig_0_bit_1 = 64'b1000110001100011000110001100011000110001100011000110001100011000;
wire [63:0] p14_dig_0_bit_2 = 64'b0010100101001010010100101001010010100101001010010100101001010010;
wire [63:0] p14_dig_0_bit_3 = 64'b0100001000010000100001000010000100001000010000100001000010000100;
wire [63:0] p14_dig_1_bit_0 = 64'b1000110001100011000110001100011000110001100011000110001100011000;
wire [63:0] p14_dig_1_bit_1 = 64'b0010010011010001010001011001001001101000101000101100100100110100;
wire [63:0] p14_dig_1_bit_2 = 64'b0001110000110000110000111000111000011000011000011100011100001100;
wire [63:0] p14_dig_1_bit_3 = 64'b1000001000001000001100000100000100000100000110000010000010000010;
wire [63:0] p14_dig_2_bit_0 = 64'b1000000111111000000011111100000011111100000001111110000001111110;
wire [63:0] p14_dig_2_bit_1 = 64'b0000110001100100011000110010001100011011000110001101100011000110;
wire [63:0] p14_dig_2_bit_2 = 64'b0010100101001001010010100100101001010010010100101001001010010100;
wire [63:0] p14_dig_2_bit_3 = 64'b0100001000010010000100001001000010000100100001000010010000100000;
wire [63:0] p14_dig_3_bit_0 = 64'b0111001110011100011000110001110011100111000110001100011100111000;
wire [63:0] p14_dig_3_bit_1 = 64'b1001101100000011011000000110110010001001100100010011011000000110;
wire [63:0] p14_dig_3_bit_2 = 64'b0100100101001001001010010010010110100100101101001001001010010010;
wire [63:0] p14_dig_3_bit_3 = 64'b0010000000100100000001001001000000010010000000100100000001001000;
wire [63:0] p14_dig_4_bit_0 = 64'b1110011100011100111000111000110001110001100011100011000111000110;
wire [63:0] p14_dig_4_bit_1 = 64'b1000101000101000101100101100100100100100110100110100010100010100;
wire [63:0] p14_dig_4_bit_2 = 64'b0000110000110000110000110000111000111000111000111000011000011000;
wire [63:0] p14_dig_4_bit_3 = 64'b0011000001000001000001000001000001000001000001000001100001100000;
wire [63:0] p14_dig_5_bit_0 = 64'b0011111110000001111110000001111110000001111110000001111110000000;
wire [63:0] p14_dig_5_bit_1 = 64'b0000000000000001111111111110000000000001111111111110000000000000;
wire [63:0] p14_dig_5_bit_2 = 64'b0000000000000001111111111111111111111110000000000000000000000000;
wire [63:0] p14_dig_5_bit_3 = 64'b0011111111111110000000000000000000000000000000000000000000000000;
wire [63:0] p14_dig_6_bit_0 = 64'b1100000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p14_dig_6_bit_1 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p14_dig_6_bit_2 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [63:0] p14_dig_6_bit_3 = 64'b0000000000000000000000000000000000000000000000000000000000000000;
wire [5:0] p14_ins = {ins[19],ins[18],ins[17],ins[16],ins[15],ins[14]};
wire [27:0] p14_outs = {
p14_dig_6_bit_3[p14_ins],p14_dig_6_bit_2[p14_ins],p14_dig_6_bit_1[p14_ins],p14_dig_6_bit_0[p14_ins],
p14_dig_5_bit_3[p14_ins],p14_dig_5_bit_2[p14_ins],p14_dig_5_bit_1[p14_ins],p14_dig_5_bit_0[p14_ins],
p14_dig_4_bit_3[p14_ins],p14_dig_4_bit_2[p14_ins],p14_dig_4_bit_1[p14_ins],p14_dig_4_bit_0[p14_ins],
p14_dig_3_bit_3[p14_ins],p14_dig_3_bit_2[p14_ins],p14_dig_3_bit_1[p14_ins],p14_dig_3_bit_0[p14_ins],
p14_dig_2_bit_3[p14_ins],p14_dig_2_bit_2[p14_ins],p14_dig_2_bit_1[p14_ins],p14_dig_2_bit_0[p14_ins],
p14_dig_1_bit_3[p14_ins],p14_dig_1_bit_2[p14_ins],p14_dig_1_bit_1[p14_ins],p14_dig_1_bit_0[p14_ins],
p14_dig_0_bit_3[p14_ins],p14_dig_0_bit_2[p14_ins],p14_dig_0_bit_1[p14_ins],ins[1]
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?