C -> assembler small function Help Me :)

  • Follow


Welcome 

I try write this function in assembler. Can you help me, Thank You

long fun (long x, long y, char z)
{
return (x+y)<<z
}

Best Greetings Lukasz

0
Reply ghuddrums 5/20/2004 7:52:42 PM

"Lukasz129" <ghuddrums@tlen.pl> wrote in message
news:55032506.0405201107.59952bd7@posting.google.com...
> Welcome
>
> I try write this function in assembler. Can you help me, Thank You
>
> long fun (long x, long y, char z)
> {
> return (x+y)<<z
> }
>
> Best Greetings Lukasz
>

In MASM it would be written somewhat like this:

fun    PROC    C    x:DWORD, y:DWORD, z:BYTE
    mov eax, x
    mov cl, z
    add eax, y
    shl eax, cl
    ret
fun    ENDP


0
Reply flekso 5/20/2004 10:19:16 PM


Lukasz129 wrote:

> I try write this function in assembler. Can you help me, Thank You
> 
> long fun (long x, long y, char z)
> {
>   return (x+y) << z;
> }

Inline it and be done with it :-)

0
Reply Nudge 5/20/2004 11:05:55 PM

Lukasz129 wrote:
> Welcome 
> 
> I try write this function in assembler. Can you help me, Thank You
> 
> long fun (long x, long y, char z)
> {
> return (x+y)<<z
> }
> 
> Best Greetings Lukasz
> 
If you want to see the assembly for it, just write it and compile it
with debug info (-g using gcc).  Then, go to gdb (if you are using some 
variant of unix), and disassemble it.

Then, open up your assembly book and review the assembly.  Remember, gdb
generates AT&T syntax, which will differ from the syntax used in NASM.

And if you want to, you can extract out the opcodes in gdb.  Then, you
can compile your original c file and open it up in a hex editor and see
the opcodes you extracted.

Brian

Note: The book Assembly Step by Step does a good job of explaining all
       this.

0
Reply tweak 6/21/2004 4:35:02 AM

tweak <xbwaichunasx@cox.net> writes:

> Lukasz129 wrote:
> > Welcome I try write this function in assembler. Can you help me,
> > Thank You
> > long fun (long x, long y, char z)
> > {
> > return (x+y)<<z
> > }
> > Best Greetings Lukasz
> >
> If you want to see the assembly for it, just write it and compile it
> with debug info (-g using gcc).  Then, go to gdb (if you are using
> some variant of unix), and disassemble it.

Or just get gcc to generate the assembly for you directly with the -S switch.


phil$ man gcc | egrep -A3 -- -S
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-pedantic]
           [-Idir...] [-Ldir...]
--
           -c  -S  -E  -o file  -pipe  -pass-exit-codes -x language  -v  -###
           --help  --target-help  --version

       C Language Options
--
       -c, -S, or -E to say where gcc is to stop.  Note that some combinations
       (for example, -x cpp-output -E) instruct gcc to do nothing at all.

       -c  Compile or assemble the source files, but do not link.  The linking
--
       -S  Stop after the stage of compilation proper; do not assemble.  The
           output is in the form of an assembler code file for each non-assem-
           bler input file specified.

--
       -S
       -E  If any of these options is used, then the linker is not run, and
           object file names should not be used as arguments.




Phil
-- 
1st bug in MS win2k source code found after 20 minutes: scanline.cpp
2nd and 3rd bug found after 10 more minutes: gethost.c
Both non-exploitable. (The 2nd/3rd ones might be, depending on the CRTL)

0
Reply Phil 6/21/2004 8:28:46 AM

4 Replies
142 Views

(page loaded in 0.128 seconds)

3/18/2013 1:41:27 AM


Reply: