//---------------------------------------------------------------- // softdivb.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 // correction: 15 MAR 2006 -- divide-overflow test revised //---------------------------------------------------------------- .section .text softdivb: # # EXPECTS: AX = dididend # BL = divisor # RETURNS: AL = quotient # AH = remainder # provided ( AH < BL ) # OTHERWISE: divide-overflow exception; # cmpb %bl, %ah # test: quotient overflow? jb okdiv8 # no, proceed with division int $0 # else simulate exception 0 okdiv8: pushl %ecx # preserve register's value movl $8, %ecx # setup for 8-bit divisor 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 .global softdivb .end