//---------------------------------------------------------------- // div_bl.s // // This file uses shift/rotate instructions to emulate with // software the Pentium's hardware divide operation for the // case when the 8-bit divisor is held in the BL register. // // programmer: ALLAN CRUSE // written on: 12 OCT 2003 //---------------------------------------------------------------- .section .text div_bl: # # EXPECTS: AX = dididend # BL = divisor # RETURNS: AL = quotient # AH = remainder # provided ( BL > AH ) # OTHERWISE: divide-overflow exception; # cmpb %bl, %ah # test: quotient overflow? jb okdiv8 # no, proceed with division orb %bl, %bl # test: divisor is zero? jnz okdiv8 # no, proceed with division int $0 # divide-overflow exception okdiv8: pushl %ecx # preserve register's value movl $8, %ecx # setup for 8-bit divisor xorb %bh, %bh # extend divisor to 16 bits nxbit8: shlw $1, %ax # double the dividend jc dosub8 cmpb %bl, %ah # can divisor be subtracted? jc nosub8 # skip subtract if bit == 1 dosub8: incb %al # record this division subb %bl, %ah # else subtrace the divisor nosub8: loop nxbit8 # and shift the result popl %ecx # restore saved register ret .globl div_bl