0

Use Lookup Tables to Optimize Square Multiples

Using a micro with no hardware multiply? You can optimize square multiples with lookup tables!

The 8088 has a hardware multiplier, but it’s quite slow:

MUL with byte arguments: 69 cycles plus 1 for each set bit in AL plus 1 if the high byte of the result is 0
MUL with word arguments: 123 cycles plus 1 for each set bit in AX plus 1 if the high word of the result is 0

Signed multiplies are even slower (taking at least 80 cycles for a byte, 134 cycles for a word), and depend on the number of set bits in the absolute value of the accumulator, the signs of the operands and whether or not the explicit operand is -0x80 (-0x8000 for word multiplies). I also measured some word IMULs apparently taking a half-integer number of cycles to run, suggesting that there’s either some very weird behavior going on with the 8088’s multiplier or that there’s a bug in my timing program (possibly both).

Can we beat the 8088’s hardware multiplier with a software routine?

To learn how to do this, read further!


Join 6,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython in 2018 – Python on Microcontrollers is here!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — @the_prepared is Soliciting Original Content on Diversity, Equity, and Inclusion

Wearables — Victorian Arduino pizzazz

Electronics — Long live labels!

Biohacking — Cryosauna Applications

Python for Microcontrollers — Building robots with Python, CRICKITS of the week, upcoming hackchat’ & more…

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



1 Comment

  1. Wow! A flash from the past. I remember doing this more than 30 years ago; are 8088’s becoming fashionable again?

    I did a little interface/bare-metal programming in the late 1970’s and I’m starting to revisit the “maker” world now. Adafruit is a spectacular resource; thanks!

Sorry, the comment form is closed at this time.