Imagesource: https://circuitverse.org/
The instruction set of the MOS 6502 is a polarizing topic. You either love it, or you hate it. There's not much in between. However, like most 8-bit CPUs of that time (apart from the 8080 and the Z80), it lacked a hardware-implemented multiplication unit.
But that would be too easy, wouldn't it? Who wouldn't relish the challenge of implementing 8, 16, or 32-bit multiplication routines in a processor cycle-optimized form based solely on a few basic mathematical operations and addition? Right? 🤓
I usually do such things right after breakfast. Just a routine.
Toby Nelson, publishing as TobyLobster, seems to feel similarly. He has documented virtually every practical approach under the sun for this very problem, measuring them for runtime and memory usage.
The result is not surprising. There's no single, best algorithm. Depending on the bit depth you want to multiply, whether signed or unsigned, each approach has its pros and cons. But for someone with a well-defined use case who needs to save a few processor cycles or RAM cells, Toby's multiply test is a veritable goldmine.
And for those who just need something to ponder and enjoy 6502 assembly, this is also a great resource.
Read the full newsletter Issue #91 of 8bitnews.io: Merry Christmas 2023
Don't want to miss updates like that? Subscribe below and receive regular content that we only share with our subscribers.