<<< Fast Multiplication and Division | Index | Displaying Binary Bits >>> |
Extended-precision integers can be stored as divided into an array of doublewords.
The low-order doubleword is stored at the lowest address (using little-endian order).
The following steps, for example, show how to shift an integer named dw_array one bit to the right:
.CONST ARRAY_SIZE = 3 .DATA ; Begin data segment dw_array DWORD ARRAY_SIZE dup(99999999h) ; 1001 pattern... .CODE ; Begin code segment ; Shift doublewords 1 bit to the right: mov esi, 0 ; 10011001... Original pattern shr dw_array[ esi + 8 ], 1 ; 01001100... highest dword -> CF rcr dw_array[ esi + 4 ], 1 ; 11001100... CF -> middle dword -> CF rcr dw_array[ esi ], 1 ; 11001100... CF -> lowest dword -> CF
Shifting any operand right by n bits divides the operand by 2n.
The steps are:
Set ESI to the offset of array.
The high-order doubleword at [ ESI + 8 ] is shifted right,
its lowest bit is copied into the Carry flag:
The value at [ ESI + 4 ] is shifted right,
the highest bit is filled from the Carry flag,
the lowest bit is copied back into the Carry flag:
The low-order doubleword at [ ESI ] is shifted right in a similar way.
At the end, carry flag CF can be inspected for the remainder of the division.
<<< Fast Multiplication and Division | Index | Displaying Binary Bits >>> |