Page 1 of 1

inline assembly questions

Posted: Fri Aug 07, 2020 4:51 am
by ITchimp
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?

Re: inline assembly questions

Posted: Fri Aug 07, 2020 5:48 am
by iansjack
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

Posted: Fri Aug 07, 2020 6:38 am
by bzt
ITchimp wrote:as movl, pushl, etc, just curious, what are the circumstance that warranted the extra l, or w, or qw
That's AT&T syntax. Sometimes you can omit the size specifier, but in general you should write that out.
iansjack wrote:How does the assembler know how many bytes you want to move?
From the argument.

For example:

Code: Select all

mov [addr], al     <- byte
mov [addr], ax     <- word
Specifying the argument's size is an AT&T syntax specific thing (GAS and GCC inline), other Assemblers, using the Intel syntax do not need that. They are smart enough to figure out the argument's size (NASM, TASM, FASM, etc.).

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
Cheers,
bzt

Re: inline assembly questions

Posted: Fri Aug 07, 2020 6:44 am
by nexos
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

Posted: Fri Aug 07, 2020 11:17 am
by iansjack
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

Posted: Fri Aug 07, 2020 4:36 pm
by ITchimp
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?

Re: inline assembly questions

Posted: Wed Aug 12, 2020 2:47 am
by iman
ITchimp wrote:between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?
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.
There is no difference in machine code generated if using Intel of GAS syntax.

Re: inline assembly questions

Posted: Wed Aug 12, 2020 4:42 am
by Octocontrabass
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..
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:also, between using att syntax/gcc as assembler, and intel syntax and nasm, which combo is better?
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.