Simple MAC (multiply-accumulate) VHDL example code.

Written by Tom on Friday 30/03/07


The role of a MAC is to add two numbers together and then add the result to the previously accumulated value, which is then restored in the registers for future accumulation.


The function add_truncate was written to detect overflow and truncate the result. If overflow occurs, the largest value (positive or negative) should be assigned the result.

("Circuit Design with VHDL" by Volnei A. Pedroni )


From GTKWaveSignals.JPG the results of the simulation can be seen.


Inputs.

a = (0,2,4,6,-8,-6,-4,-2)

b = (0,3,6,-7,-8,-8,-8,-8)

Result.

acc = (0,6,30,244,52,100,127)


Note. 244 in signed format is -12 ie 256 - 12 = 255.


All values are OK, except the last one, which is above the maximum positive value allowed for an 8-bit signed number (127). Therefore, the result was kept at 127.

("Circuit Design with VHDL" by Volnei A. Pedroni )


Download the project from here.


Use the go.bat to compile and run GTKWave.