3 ms·
Note that it's has sufficient instructions to emulate addition and subtraction, since it has compare and decrement/increment. Would take O(n) instructions to a
by aidenn0 6y ago
Note that it's has sufficient instructions to emulate addition and subtraction, since it has compare and decrement/increment. Would take O(n) instructions to add or subtract by N
- kens 6y agoThis is the algorithm the HP clock module uses to combine two BCD digits into one byte. It adds the two values by incrementing one and subtracting the other in a loop. Since the BCD digit is at most 9, this is fairly quick. I think you could implement a faster addition algorithm by testing the high order bit of the arguments, incrementing the result as needed, and then shifting. Repeating this 8 times should give you the sum, compared with up to 255 steps for the simple algorithm.
- projektfu 6y agoYou could also use a look up table in memory, a la IBM 1620. (CADET, can’t add, doesn’t even try.)