mulpdev@home:~$

Quick And Dirty Assembly

Initial page

Instruction References

AMD64 Architecture Programmer’s Manual Volume 3: General Purpose and System Instructions: https://developer.amd.com/resources/developer-guides-manuals/

Intel: https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf

NASM and Intel syntax

https://www.nasm.us/doc/nasmdoc0.html

https://cs.lmu.edu/~ray/notes/nasmtutorial/

Entry point is _start by default

section   .text
global    _start
_start:
nasm -f elf64 foo.asm -o foo.o
ld -m elf_x86_64 -entry=_start -o foo foo.o

Entry point is main by default

section   .text
global    main
main:
nasm -f elf64 foo.asm -o foo.o
gcc -m64 -o foo foo.o

AS and AT&T Syntax

From https://stackoverflow.com/a/7190511

gcc can use an assembly file as input, and invoke the assembler as needed. There is a subtlety, though:

    If the file name ends with ".s" (lowercase 's'), then gcc calls the assembler.
    If the file name ends with ".S" (uppercase 'S'), then gcc applies the C preprocessor on the source file (i.e. it recognizes directives such as #if and replaces macros), and then calls the assembler on the result.

Entry point is _start by default

.text
.globl _start
_start:
gcc -c foo.s
ld -s -o foo foo.o

OR

gcc -m64 -nostdlib -Wl,-e_start fo.S -o foo

Entry point is main by default

.text
.globl main
main:
gcc -o write write.s
gcc -o write write.s

Pure binary with no ELF format

gcc -c foo.c     
$ objcopy -O binary -j .text foo.o foo.bin
objcopy --only-section=.text --output-target binary foo.o foo.bin
gcc -Wl,--oformat=binary foo.c