Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

32 bit division in assembly language

I'm learning assembly language programming in my college course (80386 programming). Currently, I'm learning the ins and outs of 32 bit division using the EDX and EAX registers to store the remainder and quotient respectively. I want to know, why do I not get the correct output when I don't include

mov edx, 00000000h

in my program. The program either doesn't run or gives the wrong output.

Relevant source code:

mov edx, 00000000h
mov eax, 1234567Ah
div 11111111h ; now EDX=remainder, EAX=quotient

I will post the full code if needed.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

When using DIV with a 32-bit operand, it will divide the 64-bit value in EDX:EAX (high DWORD in EDX, low DWORD in EAX) by the operand and put the quotient in EAX and the remainder in EDX.

Therefore you should clear EDX prior to the division if the value you want to divide is 32 bits (fits in EAX alone). Failure to do so will result in incorrect results, or a division overflow if the quotient doesn't fit in EAX.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...