アセンブリ言語実験 10: 除算オーバーフロー問題を解く

assume cs:codesg

statcksg segment
	
	dw 16 dup(0)
	
statcksg ends


codesg segment
	
			
	start:	mov ax,statcksg
			mov ss,ax
			mov sp,32
			
			mov ax,4240h  ;被除数低16位
			mov dx,000fh  ;被除数高16位
			mov cx,0ah    ;16位除数
			
			call divdw    ;调用不会溢出的除法
			
			mov ax,4c00h
			int 21h
			
	;名称:divdw
	;功能:进行不会产生溢出的出发运算,被除数为dword型,除数为word型,结果为dword
	;参数:(ax)=dword型数据的低16位
	;	   (dx)=dword型数据的高16位
	;	   (cx)=除数
	;返回:(dx)=结果的高16位,(ax)=结果的低16位
	;	   (cx)=余数
	divdw:	push bx
	
			mov bx,ax 	;bx=L
			mov ax,dx	;ax=H
			mov dx,0 	;dx=0作为高16位
			div cx
			
			push ax 	;int(H/N)*65536入栈
			mov ax,bx	;ax=L
						;dx 余数作为高16位
			div cx
			
			mov cx,dx  ;余数
			pop dx   ;结果的高16位
			
			pop bx
			ret
			

codesg ends
end	start 

おすすめ

転載: blog.csdn.net/lcy1619260/article/details/133099269