nanenj

Hello World ASM

Aug 28th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ----------------------------------------------------------------------------------------
  2. # Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
  3. # To assemble and run:
  4. #
  5. #     gcc -c hello.s && ld hello.o && ./a.out
  6. #
  7. # or
  8. #
  9. #     gcc -nostdlib hello.s && ./a.out
  10. # ----------------------------------------------------------------------------------------
  11.  
  12.         .global _start
  13.  
  14.         .text
  15. _start:
  16.         # write(1, message, 13)
  17.         mov     $1, %rax                # system call 1 is write
  18.         mov     $1, %rdi                # file handle 1 is stdout
  19.         mov     $message, %rsi          # address of string to output
  20.         mov     $13, %rdx               # number of bytes
  21.         syscall                         # invoke operating system to do the write
  22.  
  23.         # exit(0)
  24.         mov     $60, %rax               # system call 60 is exit
  25.         xor     %rdi, %rdi              # we want return code 0
  26.         syscall                         # invoke operating system to exit
  27. message:
  28.         .ascii  "Hello, world\n"
Add Comment
Please, Sign In to add comment