flat assembler
Message board for the users of flat assembler.

Index > Main > Dividing by Multiplying

Author
Thread Post new topic Reply to topic
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
I am having a litle trouble understanding how this code works.

C code:

Code:
 
#include <stdio.h>

unsigned long foo( unsigned long a)
{

        unsigned long b;

        b = a / 10;

        return b; 

}

int main()
{        

        foo(100);                        
        return 0; 
}

    


vc++ optimized code:

Code:
 
PUBLIC  _foo
; Function compile flags: /Ogtpy
;       COMDAT _foo
_TEXT   SEGMENT
_a$ = 8                                                 ; size = 4
_foo    PROC                                            ; COMDAT
; File c:\documents and settings\kelvin\my documents\code\div.c
; Line 9
        mov     eax, -858993459                         ; cccccccdH
        mul     DWORD PTR _a$[esp-4]
        shr     edx, 3
; Line 11
        mov     eax, edx
; Line 13
        ret     0
_foo    ENDP
    


I understand how the result is produced but I don't quite understand the mathematical principles. In particular how does the compiler come up with
cccccccdH? Any ideas?

_________________
silkodyssey
Post 27 May 2006, 02:46
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
By coincidence (?) just mentioned in the other thread: http://board.flatassembler.net/topic.php?t=5302
Post 27 May 2006, 03:59
View user's profile Send private message Visit poster's website Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
Thanks for the link(s) Very Happy

_________________
silkodyssey
Post 27 May 2006, 04:17
View user's profile Send private message MSN Messenger 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.