Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

assembly - EMU8086 dividing 32 bit number by a 16 bit number gives unexpected 0 remainder

I was trying to divide (Unsigned) 8A32F4D5 by C9A5 using emu8086 tool. I expected the quotient to be AF73H and the remainder be 94B6H. After writing the following code, I was getting correct quotient but the remainder became 0000h. Am I missing something?

.MODEL SMALL
.STACK 100H
.DATA 
.CODE 

MAIN PROC 
; initialize DS
MOV AX,@DATA 
MOV DS,AX 
; enter your code here
MOV DX, 8A32H
MOV AX, 0F4D5H 
MOV BX, 0C9A5H

DIV BX

;exit to DOS 
               
MOV AX,4C00H
INT 21H 

MAIN ENDP
    END MAIN 

The output in EMU8086:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This looks like a bug in EMU8086. There is no division by zero nor is there an overflow with this unsigned division (DIV). You are correct that 0x8A32F4D5 divided by 0xC9A5 has a remainder of 0x94B6. To verify this I ran this code with Turbo Debugger in DOSBOX and got the expected results:

enter image description here

Had this been signed division using the IDIV instruction it would produce a division by zero exception because of division overflow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...