【子程序】解决除法溢出
assume cs:code
code segment
start:
mov ax,4240h ; low 16 bit of dividend
mov dx,000fh ; high 16 bit of dividend
mov cx,0ah ; divisor
call divdw
mov ax,4c00h
int 21h
divdw:
push bx
; high 16 bit: int(H / N) * 65536
; low 16 bit: (rem(H / N) * 65536 + L) / N
push ax
mov ax,dx
mov dx,0
div cx
mov bx,ax ; bx: high 16 bit
pop ax
div cx ; ax: low 16 bit
mov cx,dx ; cx: remainder
mov dx,bx ; dx: high 16 bit
pop bx
ret
code ends
end start