Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /* Reference for GNU as syntax...since I am mostly used to Intel-style assembly with NASM */
  2. /* Special things: . means the address that's being assembled currently */
  3.  
  4. .align 8 /* avoid misalignment issues */
  5.  
  6. .data /* data section */
  7. mylabel: .asciz "This is my null terminated string"
  8. nonull: .ascii "Non null terminated string"
  9. mylong: .long 1293
  10.  
  11. .bss /* Bss section..for whatever u want to put here */
  12.  
  13. .text /* text section */
  14.  
  15. /* declare start as a global */
  16. .globl _start
  17.  
  18. /*
  19. Comments are C-style with the assembler.
  20. All constants must be prepended with a $
  21. All registers must be prepended with a %
  22. AT&T syntax has this rule: origin, dest
  23. Intel syntax is the opposite: dest, origin
  24. Thus: movq $1, %rax would mean: rax = 1
  25. So, using those rules, moving the number 1 into RAX is done like this:
  26. movq $1, %rax
  27. Another thing to note is the postfix on the mnemonic. In intel syntax, mov DWORD is the mnemonic for a 32-bit move,
  28. and movl is the mnemonic for that in AT&T syntax.
  29. movq would be a quadword move, movb would by byte move and movw would be a word move.
  30. Labels are technically constants too, so to move the address of mylable into rbx:
  31. movq $mylabel, %rbx
  32.  
  33. */
  34.  
  35. fn:
  36. pushq $1
  37. pushq $mylabel
  38. popq %rax
  39. popq %rbx
  40. ret
  41.  
  42. _start:
  43. movq ($mylong), %rax
  44. movq $mylabel, %rbx
  45. call fn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement