as
. as
is to assemble the output of the compiler (gcc
) as object file which is then fed to the linker (ld
). as
invoked via gcc
, the -Wa
option forwards arguments to as
. In the following example, gcc
passes the two options -alh
and -L
to as
: gcc -c -g -O -Wa,-alh,-L file.c
a
… z
, A
… Z
, 0
… 9
, .
, _
, $
which does not start with a digit. "…"
). The "
can be escaped with \
. --multibyte-handling
option. .type
directive) .L
is a local symbol. :
). .set
and .eqv
directives. 1234:
). 1234b
and 1234f
refer to the most recent previous and the next definition of the (local) label. 1234$:
) .intel_syntax noprefix xor eax, eax .att_syntax prefix movl %adx, %eax…
-M
option of objdump
chooses the assembly dialect.
set disassemly-flavor intel
in GDB (GNU debugger).
.ascii "some text" … | Adds text without trailing zero byte |
.asciz "some text" … | Adds text with trailing zero byte. When concatenating multiple strings (separated by commas), only the final string will be zero terminated. |
.bss [n] | Assemble the following statements to the end of the bss section. ELF targets allow to add an optional subsection n which is a positive number. |
.code32 , .code64 | |
.data [n] | Assemble the following statements to the end of the data section. The optional n specifies the subsection and default to 0 if omitted. |
.def NAM , .endef | Define deubging information for the symbol NAM . The definition extends until .endef |
.end | End of source to be compiled |
.func NAM[, LBL] , .endfunc | If source is assembled with enabled debugging, .func emits the function name as debugging information. LBL is entry point for the function and resolves to NAM prepended with the leading char (which typically is an underscore or nothing, depending on the architecture). |
.globl SYM | Makes symbol visible to ld . .global and .globl are equivalent. |
.hidden , .internal , protected | ELF visiblity directives. |
.if , .else etc. | Conditional compilation |
.incbin "file"[, skip[, count]] | Include file verbatim at current location. |
.include "file" | |
.byte , .word , .long , .quad , .octa | .quad is an 8-byte integer, .octa a 16-byte integer. .short is equivalent to .word , .int is equivalent to .long . |
.loc fileno lineno [column] … | Emit DWARF2 line number information |
.macro … | Startof a macro definition |
.offset loc | Set the location counter to loc in the absolute section. loc must be an absolute expression. Do not confuse with .org |
.org new-lc , fill | |
.reloc offset, reloc_name[, expression ] | |
.section NAM | Specify the name of the section into which the following code is assembled. |
.text [n] | Assemble the following statements to the end of the text section. The optional n specifies the subsection and default to 0 if omitted. |
.weak NAMes | |
.zero n | Emit n bytes whose value is 0. |
foo.s
: .text .globl _start _start: push $11 # sys_execve popl %eax cdq pushl %edx # null-terminator byte(s) pushl $0x68732f2f # //sh pushl $0x6e69622f # /bin movl %esp, %ebx # "/bin//sh" addr movl %edx, %ecx int $0x80 # syscall
foo.S
into foo.o
: $ as foo.s -o foo.o
$ ld foo.o -o foo
$ objdump -d foo
.arch target-architecture
(to emit an error if an incompatible instruction for the target architecture is used). Compares to the -march
gcc option.
.cpu cpu-name
: to specify the target processor (also to emit errors when incompatible instructions are used). Compares to the -mcpu
gcc option.
.include file
.macro
.if
.global
(to make a symbol visible to ld).
.equ
to define a constant. (Compares to the #define
preprocessor directive)
.set
.name
to create an alias for register names
.size
.struct
.skip
.space
.text
.string
.hword
, .2byte
, .word
, .4byte
, .quad
, .8byte
for 16, 32 and 64 bit variable declarations.
.ascii
/ .asciiz
.data
.bss
(unitialized data)
.align …
.myaddr: .long
defines myaddr
to contain its own address. .=.+4
is equivalent to .space 4
-mtune
specifies the processor to optimize for. gcc -S
to create assembler code. gcc -masm=…
to select the assembly dialect. gcc -fverbose-asm
to add extra commentary to make the produced assembly file more readable.