From 91fcfdf79461fefa712e16b3d327987e0bf42798 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 20 Mar 2025 19:29:52 +0100 Subject: gas: initial notes --- src/SUMMARY.md | 1 + src/development/README.md | 1 + src/development/gas.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/development/gas.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 29f4eee..145d900 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -71,6 +71,7 @@ - [c++](./development/c++.md) - [glibc](./development/glibc.md) - [gcc](./development/gcc.md) + - [gas](./development/gas.md) - [git](./development/git.md) - [cmake](./development/cmake.md) - [make](./development/make.md) diff --git a/src/development/README.md b/src/development/README.md index 3363308..437528d 100644 --- a/src/development/README.md +++ b/src/development/README.md @@ -4,6 +4,7 @@ - [c++](./c++.md) - [glibc](./glibc.md) - [gcc](./gcc.md) +- [gas](./gas.md) - [git](./git.md) - [cmake](./cmake.md) - [make](./make.md) diff --git a/src/development/gas.md b/src/development/gas.md new file mode 100644 index 0000000..a3da13f --- /dev/null +++ b/src/development/gas.md @@ -0,0 +1,42 @@ +# gas + +## Frequently used directives +- `.byte`, `.2byte`, `.4byte`, `.8byte` to define a N byte value + ```x86asm + .byte 0xaa + .2byte 0xaabb + .2byte 0xaa, 0xbb + .4byte 0xaabbccdd + .8byte 0xaabbccdd11223344 + ``` +- `.ascii` to define an ascii string + ```x86asm + .ascii "foo" ; allocates 3 bytes + ``` +- `.asciz` to define an ascii string with `'\0'` terminator + ```x86asm + .asciz "foo" ; allocates 4 bytes (str + \0) + ``` +- `.macro` to define assembler macros. Arguments are accessed with the + `\arg` syntax. + ```x86asm + .macro defstr name str + \name: + .ascii "\str" + \name\()_len: + .8byte . - \name + .endm + + ; use as + defstr foo, "foobar" + ``` + > Use `\()` to concatenate macro argument and literal. + + +- [GNU Assembler][gas_doc] +- [GNU Assembler Directives][gas_directives] +- [GNU Assembler `x86_64` dependent features][gas_x86_64] + +[gas_doc]: https://sourceware.org/binutils/docs/as +[gas_directives]: https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops +[gas_x86_64]: https://sourceware.org/binutils/docs/as/i386_002dDependent.html -- cgit v1.2.3