flat assembler
Message board for the users of flat assembler.

Index > Main > help converting C to fasm

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 10 Nov 2011, 13:03
Hi,

I came across a bit of code in C (I think)

Code:
       op = x;
     res = 0;

        /* "one" starts at the highest power of four <= than the argument. */

      one = 1 << 30;    /* second-to-top bit set */
 while (one > op) one >>= 2;

    while (one != 0) {
             if (op >= res + one) {
                      op = op - (res + one);
                      res = res +  2 * one;
               }
              res /= 2;
           one /= 4;
         }
    


I have no idea what << and >> are Sad
Could someone translate this into fasm?

Many thanks

magicĀ²
Post 10 Nov 2011, 13:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 10 Nov 2011, 13:25
"one = 1 << 30" ---> "mov eax,1 shl 30"
"one >>= 2" ---> "shr eax,2"
Post 10 Nov 2011, 13:25
View user's profile Send private message Visit poster's website Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider 10 Nov 2011, 13:35
Code:
xor edx,edx             ;res = 0;
mov eax,dword 1 shl 30  ;one = 1 << 30
...
shr eax,2               ;one >>= 2
...
lea edx,[edx+2*eax]     ;res = res +  2 * one; 
...
shr edx,1               ;res /= 2
shr eax,2               ;one /= 4    
Post 10 Nov 2011, 13:35
View user's profile Send private message Reply with quote
Rock_maniak_forever_



Joined: 17 Feb 2010
Posts: 15
Location: Invisible country.
Rock_maniak_forever_ 10 Nov 2011, 15:25
magicSqr Compile and try to look in disassembler or debugger. I suppose it's could more be easy.
Post 10 Nov 2011, 15:25
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 10 Nov 2011, 17:28
Many thanks for the help everyone Wink
Post 10 Nov 2011, 17:28
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.