Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # quick & dirty asm tut for x86_64.
  2. #
  3. # Uses a syscall of write() and exit()
  4. #
  5. # Compile and execute like:
  6. # as -o write.o write.s
  7. # ld -o write write.o
  8. # ./write
  9. # Hi Mom!
  10. #
  11. # Tested on a x86_64 Gentoo System 2017.03.10.
  12. #
  13. # Found to be very helpful:
  14. # http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64
  15.  
  16. .data # data section
  17.  
  18. msg:    .asciz "Hi Mom!\n"  # Our string to write
  19.         len = . - msg - 1   # Length of our string to write
  20.  
  21. .text
  22. .global _start
  23.  
  24. _start:                  # Program entry point
  25.        movq  $1,%rax     # Write(); move the syscall number into %rax
  26.        movq  $len,%rdx   # Arg 3 of write(); move length of string msg into %rdx
  27.        movq  $msg,%rsi   # Arg 2 of write(); move pointer to string msg into %rsi
  28.        movq  $1,%rdi     # Arg 1 of write(); move file descriptor (STDOUT) into %rdi
  29.        syscall           # Call the Kernel
  30.        movq  $60,%rax    # Exit(); move the syscall number into %rax
  31.        xor   %rdi,%rdi   # Clear %rdi
  32.        syscall           # Call the Kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement