AmmAsm - x86-64 Assembler
Version 3.0.1
Chapter 2: AmmAsm CLI commands
2.1: The -o Option: Output File Name
AmmAsm will generate a file with the exact name which you specified after -o option.
AmmAsm can accept any file name with any extension, it does not care if file is non-.asm.
If you specified file which already exists in the folder: AmmAsm will just overwrite it.
If this option omitted - AmmAsm will generate a.out file. AmmAsm also prints message which includes
the name and size of output file, at end of compiler, and by default - compiling to ET_EXEC. For example:
$ aasm input.asm -o out
AmmAsm: Compiled successfully! out (4096 bytes)
$ aasm input.asm
AmmAsm: Compiled successfully! a.out (4096 bytes)
$ aasm input.asm -pe32+ -o bin
AmmAsm: Compiled successfully! bin (1024 bytes)
Also the usage is,
./aasm [options] "input_file"
2.2: The -c Option: Enable ELF64 object file (ET_REL)
In this mode, AmmAsm generates ELF64 object files (ET_REL) which is completely valid to link with GNU linker, GNU C Compiler, or any other toolchain. After this option, AmmAsm requires file name (similar behavior, like -o option). For example:
$ aasm input.asm -c a.o
AmmAsm: Compiled successfully! a.o (1230 bytes)
$ aasm -c a.o input.asm
AmmAsm: Compiled successfully! a.o (1230 bytes)
2.3: The -pie Option: Enable ELF64 Position independent mode (ET_PIE)
In this mode, AmmAsm turns on PIE mode (Position independent mode), and generates file with Type:DYN (Shared object file). However it is still raw executable. See section X.X to learn about PIE mode better. For example:
$ aasm input.asm -pie -o out
AmmAsm: Compiled successfully! out (4099 bytes)
2.4: The -d, --debug Option: Display a debug information while compiling
By delivering this option, AmmAsm prints debug information while compiling, such as tokens and all AST nodes. Tokens are printed after execution the lexer, and AST nodes are printed after parsing all tokens, compiling all instructions, derctives, etc. For example:
$ aasm input.asm -d
=== TOKENS DUMP (45 tokens) ===
Token[0]: type=T_SEC value='.data' line=1
Token[1]: type=T_EOL value='' line=1
Token[2]: type=T_LAB value='msg' line=2
Token[3]: type=T_U8 value='db' line=2
...
Token[42]: type=T_INS value='syscall' line=14
Token[43]: type=T_EOL value='' line=14
Token[44]: type=T_EOF value='' line=14
=== END TOKENS ===
Section[0]: name='.data' vaddr=0x401000
Label[0]: name='msg' vaddr=0x401000
Section[1]: name='.text' vaddr=0x401006
Label[1]: name='_start' vaddr=0x401006
=== AST DUMP (13 nodes) ===
AST[0]: type=AST_SECTION name='.data' addr=0x1000 vaddr=0x401000
AST[1]: type=AST_LABEL name='msg' addr=0x1000 vaddr=0x401000 global=0
AST[2]: type=AST_U8 size=6 data=[68 65 6c 6c 6f 0a] machine_code=[68 65 6c 6c 6f 0a]
AST[3]: type=AST_SECTION name='.text' addr=0x1006 vaddr=0x401006
AST[4]: type=AST_GLOBAL directive='global' labels = [ _start ]
AST[5]: type=AST_LABEL name='_start' addr=0x1006 vaddr=0x401006 global=1
AST[6]: type=AST_INS cmd='mov' operands=2 [REG32:'eax'] [IMM:0x1] inst size=5 machine_code=[b8 01 00 00 00]
AST[7]: type=AST_INS cmd='mov' operands=2 [REG32:'edi'] [IMM:0x1] inst size=5 machine_code=[bf 01 00 00 00]
AST[8]: type=AST_INS cmd='mov' operands=2 [REG64:'rsi'] [EXPR:(msg)] inst size=10 machine_code=[48 be 00 10 40 00 00 00 00 00]
AST[9]: type=AST_INS cmd='mov' operands=2 [REG32:'edx'] [IMM:0x6] inst size=5 machine_code=[ba 06 00 00 00]
AST[10]: type=AST_INS cmd='syscall' operands=0 inst size=2 machine_code=[0f 05]
AST[11]: type=AST_INS cmd='mov' operands=2 [REG32:'eax'] [IMM:0x3c] inst size=5 machine_code=[b8 3c 00 00 00]
AST[12]: type=AST_INS cmd='syscall' operands=0 inst size=2 machine_code=[0f 05]
=== END AST ===
AmmAsm: Compiled successfully! a.out (4136 bytes)
$
2.5: The -E Option: Preprocess Only
So basically, starting from v2.2 - AmmAsm has it's own preprocessor, to know about it, goto section X.X. What I was writing about?.. Uhh, yeah, basically when AmmAsm run it's pipeline, it runs firstly preprocessor, then lexer, parser and so on. This option runs preprocessor only and generates "input.asm".i. If you gave path to a file which includes more than 1 folder, AmmAsm will generate preprocessed file there (Note: This behavior might be modified in future versions). For example:
$ aasm tests/age_confirm/age_confirm.asm -E
AmmAsm: Preprocessed successfully! tests/age_confirm/age_confirm.asm.i
$ ls -lh tests/age_confirm/age_confirm.asm.i
-rw-r--r-- 1 ---- ---- 1.7K Sep 29 00:06 tests/age_confirm/age_confirm.asm.i
2.6: The -pe32+ Option: Enable PE32+ file format
By delivering this mode, AmmAsm generates output as PE32+ format file, to learn about it - goto section X.X. This option does not require any argument. For example:
$ aasm input.asm -pe32+ -o bin
AmmAsm: Compiled successfully! bin (1024 bytes)
$ aasm -pe32+ input.asm
AmmAsm: Compiled successfully! a.out (1024 bytes)
2.7: The -h, --help Option: Print help message
This option(s) prints following message:
$ aasm -h AASM - Amm Assembler Usage: ./aasm [options]Options: -o Specify the output file name. -c Compile to an object file instead of executable. -pie Enable Position Independent Executable mode. -d, --debug Display a debug information while compiling. -v Display the version of AASM and exit. -h, --help Display this help menu and exit. -E Run the preprocessor only and generate "input".i -pe32+ Compile to PE32+ file format --no-preprocess Do not run the preprocessor to increase speed Report bugs to: https://github.com/LinuxCoder13/AmmAsm/issues
2.8: The --no-preprocess Option: Skip preprocessing
As I mentioned earlier, AmmAsm has it's own build-in preprocessor. Preprocessor is isolated from whole pipeline (to learn about it, see section X.X), It allows to run AmmAsm by skipping this stage of pipeline and run lexer directly. Incompatible with -E flag.