Adding is most important operation in the computing. Using addition we can implement any operation. We have two ways to do this:1) Check every single condition
2) Implement binary adder with logic gates.
3) SecretHow its work?1) Every single condition looks like follow:
if 'A' == 1 and 'B' == 1 then set 'C' to 2
if 'A' == 10 and 'B' == 20 then set 'C' to 30
Simplest and hardest way for adding numbers. Dont need to think but a lot of work. If A and B has 5 bits values then we need 1024 cases (and x3 more nodes).2) Second way can be smaller but complicated.
Regular adders in the CPUs works with following logic. Let's look at single bit adding. Rules same as we learned in school. But only two symbols - 0 and 1 instead of ten. Simplest 1-bit adder with 2 inputs and 2 outputs has 4 cases:
Code: Select all
0 + 0 = 0 (0 carry out)
0 + 1 = 1 (0 carry out)
1 + 0 = 1 (0 carry out)
1 + 1 = 0 (1 carry out)
Maybe you know, this table looks like XOR-gate. Yea, adder working with XOR gates! In case 1+1 we have carry out (overflowing), for this we need AND gate. Pretty simple. For full-working adder we need move overflowed bit to the next part. So we need add this bit to sum of the next part of adder. For this we put one more XOR gate. And dont need another AND gate here because impossible to have such case.WikipediaBUT WE HAVE A LIMITATION!
We can't make gates with two inputs in game. So we should implement adder in another way. How?
In first evolve, opponent bots will be as input.First bot is number A, second bot is B and third is C. C=A+B. Our main bot will calculate sum of A and B and set answer with tags to third bot C.
You can noticed that we have certain condition for carrying bits. In case A.bit = 1 and B.bit = 1 carrying occured. And ripple moving to the next bits until next bit is = 0. More clearly on picture:
So for each bit we put conditions from current bit to the most significant bit. F.e. if adding number 1 to the least significant bit then we have following cases: no carry, carry to second bit, carry to third bit, ... carry to last bit. Nodes with conditions for least significant bit:
Next we make similar logic to every bit. And this logic will work in order from least to most significant bit. For correct order we should use temporary tag (on resource). Temp tag disabling next branches if certain branch was picked.
In final i created block of nodes for watching results and editing inputs. Two rows for number A and number B. Connected node mean 1, disconnected node mean 0:
Well, we have working adder in gladiabots!Lets look pictures. Bot-tagger:Bot-calculator:Final test:You can convert tags to numbers here
A = 2,3 (12 in decimal)
B = 3,4 (6 in decimal)
C = 1,4 (18 in decimal)
A = 2,3,4,5 (15 in decimal)
B = 4 (2 in decimal)
C = 1,5 (17 in decimal)