1 Attachment(s)
[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.
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.
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
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.
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.
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.
Re: gcc and inline assembly code
Thanks for your replies.
I've long since given up on this. Resolved.