Monday, March 14, 2011

Learning more in five hours than five years

Hark! For this is the first time I have made a non-eve post. Be grateful, ye masses, for I am a merciful god.

Today I learned how to multiply on a processor which is only capable of addition.

It turns out there's a trick, which is that multiplying binary numbers can be accomplished with a series of operations which does not at any point include multiplication. Check if one number ends in 1, add the second number to the result if so, drop the rightmost digit from the first number, move the second number one place to the left, and repeat until you run out of digits.

Homegrown assembly code, how adorable

In this example we multiply 27 and 32, ending up with 360 hex in register R7, which is 864 in real numbers. The loop takes 176 processor cycles.

You'd think a standard education would include maybe one month in which each day the basics of a different useful skill are taught. I'm pretty sure that month would be more useful than the remainder of primary and secondary education combined.

No comments:

Post a Comment