Thread: C and Assembly

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    10
    Rep Power
    0

    C and Assembly


    I am new to the assembly world. I am trying to use assembly with C . how do i integrate assemmbly with C.
    How do i pass the parameter.
    How do i access the arrays passed to the assemlby part of the program.
    I am using İntel- base and NASM under Linux
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2004
    Posts
    1,676
    Rep Power
    133
    Any advertisement triggered by IntelliTxt in this post is not endorsed by the author of this post.
  4. #3
  5. Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    264
    Rep Power
    124
    I know this isn't really what you asked, but GCC has an inline assembler option.

    There's a little tutorial about it here:
    http://www.ibiblio.org/gferg/ldp/GCC...bly-HOWTO.html

    To enter an ASM block in C code with GCC, you could do:
    Code:
    char* str = "abc %i\n";
    
    int main() {
        ...
        __asm__ (
            "pushl $123\n"
            "pushl str\n"
            "call printf\n"
        );
        ...
    }
    Which would printf abc 123.

    There is also an extended ASM option which allows you to use C variables, where the compiler will translate the actual addresses and such for you, then insert them into your given ASM code template.

    Syntax is a little different from Intel's, but it's not too bad, and it's convenient to use inline to experiment.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    France
    Posts
    53
    Rep Power
    15
    Here are some good tutorials on Assembly languages :

    http://www.freeprogrammingresources.com/assembly.html

    Most particularly, I recommend you to read http://savannah.nongnu.org/download/pgubook/ProgrammingGroundUp-1-0-booksize.pdf
    Although it uses the AT&T syntax, it provides a lot of useful information, especially on the C calling convention and stackframe

    Here is a link to another book with examples written in NASM : http://www.drpaulcarter.com/pcasm/

IMN logo majestic logo threadwatch logo seochat tools logo