【子程序】解决除法溢出

image

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
posted @ 2022-05-31 13:52  moon_orange  阅读(44)  评论(0编辑  收藏  举报