gas
Frequently used directives
.sectionto define a section (elf files).section .text.foo, "ax", @progbits ; defines section named .text.foo with alloc+exec perms .section .data.foo, "aw", @progbits ; defines section named .data.foo with alloc+write perms .section .rodata.foo, "a", @progbits ; defines section named .rodata.foo with alloc perms.byte,.2byte,.4byte,.8byteto define a N byte value.byte 0xaa .2byte 0xaabb # .word .2byte 0xaa, 0xbb .4byte 0xaabbccdd # .long .8byte 0xaabbccdd11223344 # .quad.asciito define an ascii string.ascii "foo" ; allocates 3 bytes.ascizto define an ascii string with'\0'terminator.asciz "foo" ; allocates 4 bytes (str + \0).macroto define assembler macros. Arguments are accessed with the\argsyntax..macro defstr name str \name: .ascii "\str" \name\()_len: .8byte . - \name .endm ; use as defstr foo, "foobar"Use
\()to concatenate macro argument and literal..reptto repeat a sequence of lines between.reptand.endr..rept 4 .4byte 123 .endr.fill cnt, elem_size, valwritecnttimesvalwith element sizeelem_size. For example one can use it to create a mbr boot record (magic number 0xaa55 at byte 511, 512)..section .boot, "ax", @progbits ; some code .. .4byte 0xff .fill 510 - (. - .boot), 1, 0x00 .2byte 0xaa55 ; as foo.s && objdump -j .boot -s ; Contents of section .boot: ; 0000 ff000000 00000000 00000000 00000000 ; .. ; 01f0 00000000 00000000 00000000 000055aaHere
.stands for the current location counter.