Last active
September 9, 2019 23:50
-
-
Save JJL772/fce92a1c157f4abd26788206d2e01ac3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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