Errata

The Art of Assembly Language

Errata for The Art of Assembly Language

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page 477
Code listing

The code listing for extended precision multiplication omits a carry if the addition of the high order bits of the result of the high order bits of the multiplier times the low order bits of the multiplicand into the partial product overflows.

Or, put another way, the instruction "adc cx, dx" in the first block of the section labeled "Multiply the H.O. word of Multiplier times Multiplicand:" can overflow, but the carry flag set by that addition is ignored.

In practice, this means the code listed will produce the wrong result when multiplying certain numbers; for example, the square of 4294967295 (= 0xFFFFFFFF), when run through the listed code will produce an incorrect result of 0xfffefffe00000001 instead of the desired 0xfffffffe00000001. This off-by-one in the most significant word is a direct result of the aforementioned dropped carry.

I'm not an expert assembly programmer, so there's likely a better solution than what follows, but I was able to correct the algorithm by modifying that section like so (note the three instructions labeled with "FIX"):

mov ax, word ptr Multiplier+2 ;Get H.O. Multiplier
mul word ptr Multiplicand ;Times L.O. word
add ax, bx ;Add partial product
mov word ptr product+2, ax ;Save partial product
xor bx bx ;FIX: zero bx to save carry
adc cx dx ;Add in carry/H.O.!
adc bx 0 ;FIX: Don't forget carry!

mov ax, word ptr Multiplier+2 ;Multiply the H.O.
mul word ptr Multiplicand+2 ; words together.
add ax, cx ;Add partial product
adc dx, bx ;FIX: Add in two carries (one from just above, one from earlier)
mov word ptr Product+4 ax ;Save partial product
mov word ptr Product+6 dx


This change introduces two instructions and modifies a third: an xor to zero bx, an adc to save the carry flag into bx, and then changes the final adc in the algorithm to use that saved carry bit in bx.

Anonymous  Nov 18, 2017