SebLague / Digital-Logic-Sim

Home Page:https://sebastian.itch.io/digital-logic-sim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A question about the adder(s)

crispeeweevile opened this issue · comments

So, I'm a little confused about the basic adder (3 inputs, 2 outputs) when you add the two numbers, lets say 0b and 1b you just get 1b but let's say you have 1 in both (1b + 1b) that should be 10b right? so in the future if we use the carry bit, shouldn't we treat it as 2d and not 1d?

The fact that it's treated as just 1d (or 01b) is obvious in the adder if you add 00b+00b+Cin(as 1) which will get you a result of 01b
Everything I've googled seems to have given me the exact same answer, so I guess it's not wrong, but there must be something I'm misunderstanding

What are you referring to? A part in a video?

Well, since the binary adder allows you to add up to 2 numbers, which could be be 1 and/or 0 that allows your result to max out at 2, but when you get 2, the carry bit has no indicator that it actually represents 2 and not just the standard 1.

2 in an adder is Carry HI (on) and SUM LO (off). A full adder (what you described in your OP, A and B in, and CIn, with SUM and COut) can output up to 0b11 (3). To go higher, you pass the COut from one Full Adder into the CIn on the next. Also, both the SUM and the COut are 1 bit, neither of them are "2D", they both only hold either a single 0 or 1 per adder. A value of 0b01 = SUM HI and COut LO, a value of 0b11 = SUM HI and COut HI. I hope this clears it up for you a bit.

@crispeeweevile
A single adder allows you to add two or three bits. You are adding single bits and get a multi-bit output.

Have a look at the truth-tables, and you'll notice that the C & S outputs are the binary 0 to 3.

Half-Adder

a b C S Decimal
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 0 2

Full-Adder

a b c C S Decimal
0 0 0 0 0 0
0 0 1 0 1 1
0 1 0 0 1 1
0 1 1 1 0 2
1 0 0 0 1 1
1 0 1 1 0 2
1 1 0 1 0 2
1 1 1 1 1 3

To add more than bits together, you can chain multiple adders.

This example can add two 2bit numbers (0-3) and outputs one 3bit number (0-6/7)

image

With the following truth table:

a1 a0 dec b1 b0 dec o2 o1 o0 dec
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 1 1
0 0 0 1 0 2 0 1 0 2
0 0 0 1 1 3 0 1 1 3
0 1 1 0 0 0 0 0 1 1
0 1 1 0 1 1 0 1 0 2
0 1 1 1 0 2 0 1 1 3
0 1 1 1 1 3 1 0 0 4
1 0 2 0 0 0 0 1 0 2
1 0 2 0 1 1 1 0 0 4
1 0 2 1 0 2 1 0 0 4
1 0 2 1 1 3 1 0 1 5
1 1 3 0 0 0 0 1 1 3
1 1 3 0 1 1 1 0 0 4
1 1 3 1 0 2 1 0 1 5
1 1 3 1 1 3 1 1 0 6

You see that I don't use the carry in for the first full-adder, it could as well be just a half adder.

In reality, you would use that Carry-In for your ALU to simplify often occurring operations. You can add 1 to a number without having to load a 1 into one of the registers. It also allows negating a number in a single cycle. (invert + 1)

And you wouldn't use the last Carry-Out in your number. The carry would be the Carry-Flag.

So in a 4-bit AU, you would have:
INPUT
a3, a2, a1, a0
b3, b2, b1, b0
carry-in (INC)

OUTPUT
o3, o2, o1, o0
carry-out
overflow-out

@MrEbbinghaus
Ohhh, okay. I understand now. Thank you very much for explaining it to me

@crispeeweevile
issue solved? >> close issue?