when I code in inline assembly... I usually use generic assembly instruction
such as mov, push, but in linux source assembly i have seen those being written
as movl, pushl, etc, just curious, what are the circumstance that warranted the extra l, or w, or qw
I realize that this should be automatic... when I compile c code into assembly movl pushl
appears. but when should I code explicitly in those?
inline assembly questions
Re: inline assembly questions
Well, as one example, what if you do a move immediate to a memory location? How does the assembler know how many bytes you want to move?
Re: inline assembly questions
That's AT&T syntax. Sometimes you can omit the size specifier, but in general you should write that out.ITchimp wrote:as movl, pushl, etc, just curious, what are the circumstance that warranted the extra l, or w, or qw
From the argument.iansjack wrote:How does the assembler know how many bytes you want to move?
For example:
Code: Select all
mov [addr], al <- byte
mov [addr], ax <- word
For immediates, they usually require a size specifier, just like AT&T, but only for immediates. For example in FASM:
Code: Select all
mov word [addr], 1
bzt
Re: inline assembly questions
That is why I try to hide my ASM in external files. I hate writing inline ASM. I put most of my ASM in external files compiled with NASM. You will have to use inline ASM in some places, but I try to steer clear of it.
Re: inline assembly questions
But it's nothing to do with whether the assembler is inline or not. Sometimes there is ambiguity about an instruction unless you use a size qualifier.
Re: inline assembly questions
if you do asm volatile, then all of those assembly code will be respected by the, making them a lot closer to the real nasm..
also, between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?
also, between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?
Re: inline assembly questions
I would like to use Intel syntax. Many assemblers including NASM, MASM, FASM, and TASM cover this syntax, and in my opinion easier to read and follow.ITchimp wrote:between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?
There is no difference in machine code generated if using Intel of GAS syntax.
-
- Member
- Posts: 5572
- Joined: Mon Mar 25, 2013 7:01 pm
Re: inline assembly questions
If you want it to be like NASM, don't use inline assembly. You can write pure assembly files and assemble them with gas (with or without GCC as a frontend).ITchimp wrote:if you do asm volatile, then all of those assembly code will be respected by the, making them a lot closer to the real nasm..
Don't forget that GCC also supports Intel syntax. I prefer NASM since I like its syntax better than GCC's Intel syntax, but you can't write inline assembly with NASM.ITchimp wrote:also, between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?