Results 1 to 7 of 7

Thread: [RESOLVED] gcc and inline assembly code

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Resolved [RESOLVED] gcc and inline assembly code

    I need guidance on inlining asm code in my linux C programs. I have some intel-assembler experience and I have made a few stumbling and generally failed efforts to get to grips with AT&T syntax.

    However I was trawling through the gcc info pages and found a switch called "-masm=".

    I have discovered (excitedly) that gcc will apparently compile a block of asm that is written as regular intel style code. See the screenshot attached to see my simplest-possible test.

    My question is this:
    Given that A) intel asm is easy, B) AT&T is hard, C) AT&T is gcc and unix standard, D) I have not been able to find any GOOD sources of information (reference or tutorials) on AT&T assembly.

    What should I use, intel or AT&T? I do want to conform to industry standards but at the same time AT&T is a nightmare.

    I'm willing to put time into learning AT&T, but only if it's going to be time-well spent in the long run, from where I'm standing (angry and frustrated) it just doesn't look that way.

    I need the advice of a more experienced unix assembly coder.
    Attached Images Attached Images  
    Last edited by wossname; Mar 26th, 2008 at 02:53 PM.
    I don't live here any more.

  2. #2

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: gcc and inline assembly code

    And secondly, if anyone does know a good source of AT&T/Unix tutorials or reference material online then PLEASE let me know, the places I've found so far (http://asm.sourceforge.net/ , http://asm.sourceforge.net/articles/linasm.html, http://www.int80h.org/) generally lack the fundamentals and also how to get around compilation problems.
    I don't live here any more.

  3. #3
    Hyperactive Member Iron Skull's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    325

    Re: gcc and inline assembly code

    I'd go for Intel ASM anyday.
    The reason is that I am in touch with that every day. And that I think AT&T ASM is Harder but it doesn't add anything.
    Though I am still looking for a way to use intel ASM in my GCC C++ Code.

    I did code both Assembler Languages on Linux. And I think AT&T is a load of Rubbish...

    Well, have fun, hope I hlped.

    Oh NASM is a GREAT Assembler.

    Cheers,
    Robin

    506C65617365205261746520506F7374732E2E2E

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: gcc and inline assembly code

    Certainly the syntax is a lot harder in AT&T assembler but I do think it add's something - re-tartegability (I made that word up clearly). AT&T syntax doesn't tie the code to any particular CPU, it's probably the closest thing to portable ASM we're likely to get.

    I havent really done much ASM since I started this thread so I guess I'll play it by ear.
    I don't live here any more.

  5. #5
    Hyperactive Member g4hsean's Avatar
    Join Date
    May 2006
    Posts
    267

    Re: gcc and inline assembly code

    Wait a minute.... the output of your program cant be right.... when a program terminates on a Linux system isn't the %ebx register used as the exit status?

    such as:
    Code:
    .section .text
         .globl _start
    _start:
             movl $1, %eax
             movl $123, %ebx
             int $0x80
    the output will look like this:

    $as -o test.o test.s
    $ld -o test test.o
    $./test
    $echo $?
    123
    $

    Or maybe the C program is moving the %eax register to the %ebx register.... Hmm too bad im not in vmware.
    Coding's a Breeze if you'r at ease! GOD THATS CORNY!!
    -

  6. #6
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: gcc and inline assembly code

    Quote Originally Posted by wossname
    Certainly the syntax is a lot harder in AT&T assembler but I do think it add's something - re-tartegability (I made that word up clearly). AT&T syntax doesn't tie the code to any particular CPU, it's probably the closest thing to portable ASM we're likely to get.

    I havent really done much ASM since I started this thread so I guess I'll play it by ear.
    Honestly woss, the very second a programmer decides to use assembly language, that programmer is starting to worry about platform specific information. The basic rule of thumb is if you need asm to be portable, then you are far better off staying with a high level language.

    With ASM you need to be very specific about the hardware. Every processor has advantages in this or that and disadvantages in this and that. Some processors do inc faster then add, others do add faster then inc. Some will go apeshit nuts if you have misaligned data, others will just tax you and keep on going as if it never happened.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  7. #7

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: gcc and inline assembly code

    Thanks for your replies.

    I've long since given up on this. Resolved.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width