flat assembler
Message board for the users of flat assembler.

Index > Main > [solved] DIV problem

Author
Thread Post new topic Reply to topic
rc



Joined: 03 Nov 2019
Posts: 55
Location: Germany
rc 16 Mar 2020, 20:46
Hello,

can somebody tell me why this produces an integer overflow when i do the division?

Code:
format PE
entry main
section '.code' code readable executable

main:
        int3
        mov eax, 4
        mov ecx, 2
        div ecx
        push eax      


4 is divided by 2, that shouldn't be a problem? Or am i missing something?
Post 16 Mar 2020, 20:46
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 514
Location: Czech republic, Slovak republic
Feryno 16 Mar 2020, 20:54
but what is the input value in edx ?
if input edx 2 or more the result cannot fit into 32 bit register
try this:
Code:
mov eax,4
xor edx,edx    
Post 16 Mar 2020, 20:54
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
rc



Joined: 03 Nov 2019
Posts: 55
Location: Germany
rc 16 Mar 2020, 21:01
Oh.. i guess i missunderstood div... ?
Code:
mov ecx, 2
div ecx    

So "div ecx" in my case divides whatever is in edx by 2?
I thought div ecx divides whatever is in eax by ecx in this case. And the result gets stored back into eax.

[EDIT]

Oh now i understand. div always divides the 64 bits value accross EDX:EAX by a value. Didn't know that. Thank you!
Post 16 Mar 2020, 21:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 17 Mar 2020, 17:02
Well, it is definitely unfortunate that I have still not recorded part 10 of my video tutorial, which I planned to be about MUL/DIV. My fault, but I had to postpone continuation of this series for various unrelated reasons.
Post 17 Mar 2020, 17:02
View user's profile Send private message Visit poster's website Reply with quote
rc



Joined: 03 Nov 2019
Posts: 55
Location: Germany
rc 17 Mar 2020, 18:53
Tomasz Grysztar wrote:
Well, it is definitely unfortunate that I have still not recorded part 10 of my video tutorial, which I planned to be about MUL/DIV. My fault, but I had to postpone continuation of this series for various unrelated reasons.


@Tomasz Grysztar:
Well, we all have stuff to do besides our hobbies Smile.
I'm following your tutorial series since the beginning and hope you will find the time to continue soon. And i hope this series is going to be a really long series Smile. They are really helpful. Thanks for taking the time to teach the ones that are new to f/asm.
Post 17 Mar 2020, 18:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.