Skip to content

Instantly share code, notes, and snippets.

@JJL772
Last active September 9, 2019 23:50
Show Gist options
  • Save JJL772/fce92a1c157f4abd26788206d2e01ac3 to your computer and use it in GitHub Desktop.
Save JJL772/fce92a1c157f4abd26788206d2e01ac3 to your computer and use it in GitHub Desktop.
/* Reference for GNU as syntax...since I am mostly used to Intel-style assembly with NASM */
/* Special things: . means the address that's being assembled currently */
.align 8 /* avoid misalignment issues */
.data /* data section */
mylabel: .asciz "This is my null terminated string"
nonull: .ascii "Non null terminated string"
mylong: .long 1293
.bss /* Bss section..for whatever u want to put here */
.text /* text section */
/* declare start as a global */
.globl _start
/*
Comments are C-style with the assembler.
All constants must be prepended with a $
All registers must be prepended with a %
AT&T syntax has this rule: origin, dest
Intel syntax is the opposite: dest, origin
Thus: movq $1, %rax would mean: rax = 1
So, using those rules, moving the number 1 into RAX is done like this:
movq $1, %rax
Another thing to note is the postfix on the mnemonic. In intel syntax, mov DWORD is the mnemonic for a 32-bit move,
and movl is the mnemonic for that in AT&T syntax.
movq would be a quadword move, movb would by byte move and movw would be a word move.
Labels are technically constants too, so to move the address of mylable into rbx:
movq $mylabel, %rbx
*/
fn:
pushq $1
pushq $mylabel
popq %rax
popq %rbx
ret
_start:
movq ($mylong), %rax
movq $mylabel, %rbx
call fn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment