Advertisement
Guest User

movabs

a guest
Feb 1st, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #
  2. # $ gcc -nostdlib -Wall -shared -fPIC hello_exit.S -Wl,-soname,libhelloexit.so.1,-export-dynamic -o libhelloexit.so.1.0
  3. #
  4. # .macro
  5. .macro fn name
  6. .global \name
  7. .type \name, @function
  8. \name:
  9. .endm
  10.  
  11. .data
  12. hw:
  13. .ascii "Hello, world\n"
  14. .set hs, .-hw
  15.  
  16. .text
  17. # very usefull function
  18. fn es_hello_world
  19. # write(1, message, 13)
  20. movq $1, %rax # system call 1 is write
  21. movq $1, %rdi # file handle 1 is stdout
  22. movabs $hw, %rsi # address of string to output
  23. movabs $hs, %rdx # number of bytes
  24. syscall # invoke operating system to do the write
  25. retq # go back
  26.  
  27. fn os_exit
  28. # exit(0)
  29. movq $60, %rax # system call 60 is exit
  30. syscall # invoke operating system to exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement