Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # quick & dirty asm tut for x86_64.
- #
- # Uses a syscall of write() and exit()
- #
- # Compile and execute like:
- # as -o write.o write.s
- # ld -o write write.o
- # ./write
- # Hi Mom!
- #
- # Tested on a x86_64 Gentoo System 2017.03.10.
- #
- # Found to be very helpful:
- # http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64
- .data # data section
- msg: .asciz "Hi Mom!\n" # Our string to write
- len = . - msg - 1 # Length of our string to write
- .text
- .global _start
- _start: # Program entry point
- movq $1,%rax # Write(); move the syscall number into %rax
- movq $len,%rdx # Arg 3 of write(); move length of string msg into %rdx
- movq $msg,%rsi # Arg 2 of write(); move pointer to string msg into %rsi
- movq $1,%rdi # Arg 1 of write(); move file descriptor (STDOUT) into %rdi
- syscall # Call the Kernel
- movq $60,%rax # Exit(); move the syscall number into %rax
- xor %rdi,%rdi # Clear %rdi
- syscall # Call the Kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement