Adder/Subtractor - Page 1
Forum section: electronics / beginners

author: Cujo
author_rank: Regular Contributor
timestamp: September 19, 2025, 01:37:56 am
content: I built an adder/subtractor circuit that uses two’s complement applied to the B input, allowing it to perform A ± B. A toggle switch enables or disables subtraction mode.Now, I want to add another feature so the circuit can compute 0 – A = –A. To do this, I attempted to multiplex the A input so that B can be switched between 0 (ground). Then, by using another multiplexer, I tried setting A = B to achieve the desired operation.However, when I implement this modification, the entire circuit breaks and none of the functions work correctly.

author: ledtester
author_rank: Super Contributor
timestamp: September 19, 2025, 03:04:27 am
content: It's hard to understand your diagram without any labels. (Edit: Ok, I see them now - they are really tiny!)I had a lot of time on my hands, so I whipped this up in Falstad...Click on the H and L's in the Input box to change the inputs. (Also make sure the RUN/Stop button is not red -- red means the simulation is not running.)(Falstad link)The OP input is L for add and H for subtract. The ZERO input selects whether the A input is zeroed or passed through.Note that the displays are in decimal (not hex).Update: Ok, I see you want to compute -A not -B.

author: jwet
author_rank: Frequent Contributor
timestamp: September 19, 2025, 03:10:40 am
content: Wow- that's a pretty impressive effort ledtester!I was only going to ask, what sim environment or hardware he did his logic in. Falstad a good tool for this.

author: ledtester
author_rank: Super Contributor
timestamp: September 19, 2025, 03:16:34 am
content: Well, shucks :-)Falstad is actually not that great for logic simulation. I choose it because it was something people could run and play with without downloading anything. Also -- it was capable of implementing this circuit. It doesn't implement a lot of devices but it does allow you to create a custom logic device which is how I did the MUX.

author: Cujo
author_rank: Regular Contributor
timestamp: September 19, 2025, 03:22:30 am
content: That makes sense for -B. If the value is negative, it’s straightforward, since two’s complement is already applied to input B. But to compute -A, you need to apply two’s complement to A as well. At the same time, two’s complement still has to be applied to B so that the operation correctly evaluates to A ± B. It's kind of like needing to MUX between two inputs that has two's complement applied to it. Still not sure if my setup was correct though

author: jwet
author_rank: Frequent Contributor
timestamp: September 19, 2025, 03:24:50 am
content: That last sentence was a question but got borked- IS falstad a good sim environment? You answered. Again, good effort, a credit to the discourse here.

author: ledtester
author_rank: Super Contributor
timestamp: September 19, 2025, 03:46:21 am
content: Quote from: Cujo on September 19, 2025, 03:22:30 amYes - I realized only after I posted that you wanted to be able to compute -A.This circuit is able to compute A+B, A-B and -A:(Falstad link)See the table below the input box for how OP and ZERO control OUTPUT.

author: Cujo
author_rank: Regular Contributor
timestamp: September 19, 2025, 04:18:24 am
content: Thank you that works. I almost had it 😅

author: Cujo
author_rank: Regular Contributor
timestamp: September 22, 2025, 09:47:08 am
content: Hello, I am trying to expand on this Adder/Subtractor/Negative further. I would like to add two additional functions: absolute(A–B) and minimum(A, B).For the absolute value function, the idea is to use a 4-bit comparator that provides the signals A<B, A>B, and A=B. If A>B, the circuit outputs A-B directly. Otherwise, it flips the subtraction and outputs B-A to ensure the result is always positive.For the minimum function, reuse the same comparator. Based on whether A<B or B<A, the smaller of the two inputs will be selected and passed to the output.I am a bit stuck on how to implement this into my current logic design. This is on what I have done so far based on what i have described here.