OpenCores
URL https://opencores.org/ocsvn/vtach/vtach/trunk

Subversion Repositories vtach

[/] [vtach/] [trunk/] [bcdadd.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wd5gnr
`timescale 1us/1ns
2
 
3
/* Flull blown BCD adder -- takes number + sign bit and returns result in same format
4
Note the number is always a positive representation
5
so that 1001 is -1
6
 
7
Also note that BCD and hex are exactly the same except for legal digits
8
do 13'h1001 is actually BCD -1 */
9
 
10
module bcdadd(input [16:0] a, input [12:0] b, output [16:0] z);
11
  wire [16:0] ain;
12
  wire [12:0] bin;
13
  wire [16:0] zout;
14
  wire [16:0] ztemp;
15
  // The bcdneg modules return either a positive # or a 9's compliment #
16
  bcdneg17 aneg(a,ain);
17
  bcdneg13 bneg(b,bin);
18
  // Add the converted numbers
19
  usum adder(ain,bin,zout);
20
  // the bcdneg module is reversible so if we feed it 9's compliment we get
21
  // our format back out
22
  bcdneg17 zneg(zout,ztemp);
23
  // sometimes you get -0 and we don't want that so filter it here
24
  assign z=(ztemp==17'h10000)?(17'h00000):ztemp;
25
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.