4 ms·
First of all the machine should have enough RAM to hold the numbers you want to add. Say two 3-bit numbers a and b: a2 a1 a0 + b2 b1 b0 ---------- =
by jonsen 10y ago
First of all the machine should have enough RAM to hold the numbers you want to add.
Say two 3-bit numbers a and b:
a2 a1 a0
+ b2 b1 b0
----------
= c2 c1 c0
Then to do the addition by testing one bit at a time think like
if (a0==0)
if (b0==0)
c0 = 0;
else
c0 = 1;
else
if (b0==0)
c0 = 1;
else
c0 = 0;
...
- cpr 10y agoAnd how do you store the carry bits (this machine only has 2 bits of state)? Or do you encode carries by pure branching?
- jonsen 10y agoIt would be tedious to do it all by pure branching. You would need a 64-way branch for c2. If you can't spare one separate RAM bit for a carry you could store the carries in the c2 location and start the computation of c2 by if (c2==...