#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    using assembly with g++


    how do enter an assembly block? this is what im used to doing:
    Code:
    int main(int argc, char *argv[])
    {
            char a = 'a';
            _asm
            {
                    movl a,EAX;
                    and 0x01000001,EAX;
                    mov EAX,a;
            }
            printf("%x\n",a);
    
            return 1;
    }
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    It appears to me that it may vary between implementations of g++ what the syntax will be and whether inline assembly is even supported.

    At http://cs.wwc.edu/~aabyan/Unix/Assembly.html I found instructions for inline assembly with g++, but it seems more DJGPP-oriented. Their code would not compile with my MinGW gcc nor g++; it would not even recognize the asm keyword. I also could find no reference to assembly in the LibC help file.

    On my Redhat7 box, my version 2.96 gcc did recognize asm, but I had some compile errors.

    So you might have to do a bit of testing and searching for your particular g++. The key appears to be that you shouldn't give up too quickly if you run into problems.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    thanks scorpions, that answered my question. also made me realize assembly is a lot different than im used to, (not to mention the pain of writing each line like this: asm("movl a,%eax"); )
    Last edited by infamous41md; May 6th, 2003 at 11:18 AM.
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Originally posted by infamous41md
    (not to mention the pain of writing each line like this: asm("movl a,%eax"); )
    You should be able to write multiple lines of assembly code in a single asm statement; eg:
    Code:
    asm("incl x 
                movl x, %eax 
                imull y 
               movl %eax,x 
              ");
    See whether your compiler requires a different syntax for this.

IMN logo majestic logo threadwatch logo seochat tools logo