Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement