Multiply Two Numbers Using Shifts

This function multiplies two numbers using shift and add operations.

The parameters are passed on the stack. The procedure stores the two parameters in the word registers bx and dx, and accumulates the result in eax, providing 16 bit ¥ 16 bit = 32-bit multiplication. For each bit that is on in dx, it adds the value “bx shifted left the appropriate number of bits” to eax. When it has checked every bit in dx, the correct result will be in eax, which is where the procedure is defined to return it.

The procedure does preserve the passed-in value of registers, and is responsible for popping parameters off the stack. ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.