[Digital Electronics] 8-Bit Ripple-Carry Adder

Patric20878

Terrarian
Few weeks ago, when I first saw DicemanX's binary calculator, I had set out on making an improved, more efficient design. And the result is my highly compact binary ripple-carry adder, adding each bit in only 7 ticks, which is a far faster design (around 4.6x faster on 24 bit adders, faster for larger additions). So for example, a 20 bit version of this ripple-carry adder would take no more than 2.5 seconds to add two 6 digit numbers, such as 954,358 + 853,596. Design shown below:

Adder performing 011(red) + 101(blue) = 1000(green), rippling changes across with skeletons:
43zlINW.jpg


The wiring (was frustratingly tricky to compact :p):
J0XO8lC.jpg


2 levers on each adder are the inputs. The red and blue torch indicates which inputs are currently on and off, and the green torch below them are the output. I arranged the torches in a way that looks exactly like adding 2 numbers on paper, except in binary instead of decimal of course, so it should be pretty intuitive to add them up yourself even without the adder doing it, if you know binary.

In this type of adder, IRL digital electronics circuitry logic is used to perform calculations rather than the hoiktronics methods seen so far. The 8-bit RC adder consists of 8 completely identical full adders. In each addition, each digit of the 2 binary numbers are added together, and any carries are then added to the next bit adder, very similar to how addition and regrouping works when adding on paper. Using this series of full adders, which differ from half adders in the fact that they can accept and calculate with carries, any changes in input "ripple" changes across to the final adder, updating everything on the way, thus the name. I also made this design with the strict goal that this imitates digital electronics as close as possible rather than use specific Terraria game mechanics to accomplish the goal, so as such, the adder is fully automatic and each logic gate simulates digital electronics as much as possible, something that Terraria makes difficult to do since circuitry here works differently. Any change in the input levers will immediately start updating the output sum without any additional lever pulls, and no resets are required after each addition, as their states are all stored and can be operated as many times as you'd like with no limit.

3 types of logic gates are used. I won't cover each logic gate's truth table as that can be Googled relatively easily, but to calculate the digit place being added, 2 XOR logic gates are used, which are 2 levers of each full adder and its previous carry. Now since Terraria circuitry works differently (inputs give a pulse signal instead of sustained, outputs are toggled only), the 2 levers that normally make OR logic in digital electronics circuitry makes XOR here. Then, to calculate the carry, input 1 is AND'd with input 2, (input 1 XOR input 2) is AND'd with its previous carry, and then finally, the 2 AND outputs are OR'd together to form the decisive carry output of either 1 or 0. And this process repeats with each full adder, the result in-game literally being outputs being updated by skeletons rippling through the ripple-carry adder. Looks pretty neat actually. :D

In short, the logic works like this:
Input 1: a
Input 2: b
Previous Carry: c

Half adder (can only do 1-bit addition):
Output: a XOR b
Carry: a AND b

Full adder:
Output: (a XOR b) XOR c
Carry: (a AND b) OR [(a XOR b) AND c]

Thanks to DicemanX for helping me figure how to simulate IRL logic gates with hoiktronics and getting me familiar with Terraria-specific game mechanics that I needed to make this design. DicemanX and inomanoms will also finish a similar, yet different design to this that will also use ripple-carry logic. Like his old design, it will be a calculator rather than a RC adder, as it won't be automatic and also won't simulate digital electronics circuitry, but as it will be taking full advantage of hoiktronics, it'll be even faster than this design. And I hope from here on out after I introduced the much more efficient digital electronics way of doing everything computing related, knowledge on this area will advance rapidly. Demo world attached, try adding some numbers with it and then confirm it with your computer's built in calculator, and have a blast or something :D

P.S. I'm just going to leave this here for knowledge reference or something since I no longer have any interest in engineering further in Terraria, but if you combine the efficient ripple-carry logic with hoiktronics, take it a step further by upgrading it to a carry lookahead adder (even faster), then using that with shift registers to build a multiplier, you will speed up your binary multiplier MASSIVELY, diceman. Ignoring the addition part, the difference here if multiplying very large numbers such as 2^20 (1,048,576) to itself would roughly be the difference between your current way of adding 1 million to itself 1 million times (let's call that 1 million units of time) vs multiplying 1000..(20 zeros) to each of the 20 binary digits on the other number, then adding the subtotals together, which would be a total of 21 units of time. AKA 47,620 times faster (lol) And the formula to compare speed difference would be around x/log2(x), x being the 2nd number in the multiplication, in decimal base. Looking forward to what you can do. :)
 

Attachments

  • 8-Bit_RC_Adder.zip
    938.3 KB · Views: 224
Last edited:
Hehehe, DicemanX got one-upped, priceless.

You'll have to wait and see what I post a little later first ;).

For now, let's appreciate Patric20878's hard work in making an efficient and fast version of the adder!
 
True, this should not be easy, I took a look at the map and this certainly wasn't easy! though Diceman's is a lot more organized and efficient.
 
Back
Top Bottom