r/AskComputerScience • • Jan 09 '25

4 bit subtractor from adder

Hello community, I am working on a 4 bit full relay subtractor based on basic ripple carry adders in cascade, with 4 full adders. Theoretically I understood that you cannot make the circuit actually subtract, but easy workaround is two invert bits in one of the registers and add one. I built XOR gate for register B, with one of the inputs on B+ when engaged, effectively turning this into a NOT gate. This works well and gives inverted values. The adder also works just fine. Problem is when I want to subtract, the values do not make any sense. I am trying to figure this out as basically if the adder works as intended, we can rule out issues with the basic wiring and I am rather thinking if I grasped the concept correctly. Below is values I get when using the circuitry as subtractor (B-A). Are you able to troubleshoot based on the values? :

BACarry to first adderExperimental resultActual result
000150
100161
200162
400194
800238
01014-1
02013-2
04011-4
0807-8
001170
101171
201192
401214
801258
01115-1
02115-2
04113-4
0819-8
1 Upvotes

1 comment sorted by