Assembly: division
How to divide large numbers with assembly language, and where the results end up.
numbers are most commonly divided by smaller numbers (eg a 16 bit number divided by an 8 bit number)
The numerator must be placed in specific registers and the denomenator is supplied as a single operand.
This example takes a possible 32 bit number and shows how to move it’s contents to the correct 16 bit registers.
XOR EDX,EDX ;clear EDX
;place number to be divided into EDX (32-bit)
XOR CX,CX ;clear CX
;place 16-bit denomenator into CX
do_division:
mov AX,DX ;move least significant bits to AX
shr EDX,16 ;shift most significant bits to DX
div CX ;divide DX:AX by CX
;quotient in AX
;remainder in DX
that’s all there is to it. 16 bit numbers are of course easier to deal with as there is no bit shifting involved as DH, and DL are available directly.
Thus is this result was a fraction the solution would be AX + DX / CX where DX/CX is the remainder over the divisor as the fractional part of the solution
Questions/Comments: william_a_wilson@hotmail.com





