Input is two 3 digit binary numbers (10 bits each)

Output is a 6 digit BCD number (4 bits for each digit)

Verilog Modules

The code was split into three modules. A Binary to BCD converter module, a BCD multiplication module, and a main module for connecting the two others together.

Binary to BCD Converter

This module has an input of a 10 bit binary number and outputs 3 BCD digits that are 4 bits each. The algorithm for converting binary to BCD is the following:

If a BCD digit is >= 5, add 3 to it

Shift Left

If no more shifts remain in the binary number – done.

Example for 156 in binary

Hundreds

Tens

Ones

Binary

Instruction

10011100

Initial

1

0011100

Shift

10

011100

Shift

100

11100

Shift

1001

1100

Shift

1100

1100

Add 3

1

1001

100

Shift

1

1100

100

Add 3

11

1001

00

Shift

11

1100

00

Add 3

111

1000

0

Shift

1010

1011

0

Add 3

1

0101

0110

Shift

BCD Multiplication

Multiplication is based on array multiplication with an “A*B + C + D” module.

As seen in the code, the algorithm for the module is

Initially set all output registers to 0

Add B to output A times (effectively doing A*B)

After each addition do BCD correction

Add C

Do BCD correction

Add D
* Do BCD correction

Main Module

After both modules were made, the they were connected together in the main module.

Testing

As for the testing bench for this module, the following code was used: