3 ms·
This 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
by kens 6y ago
This 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.)