Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2.     global _start           ;must be declared for linker (ld)
  3.  
  4. _syscall:      
  5.     int 0x80        ;system call
  6.     ret
  7.  
  8. _start:             ;tell linker entry point
  9.  
  10.     push    dword len   ;message length
  11.     push    dword msg   ;message to write
  12.     push    dword 1     ;file descriptor (stdout)
  13.     mov eax,0x4     ;system call number (sys_write)
  14.     call    _syscall    ;call kernel
  15.  
  16.                 ;the alternate way to call kernel:
  17.                 ;push   eax
  18.                 ;call   7:0
  19.  
  20.     add esp,12      ;clean stack (3 arguments * 4)
  21.  
  22.     push    dword 0     ;exit code
  23.     mov eax,0x1     ;system call number (sys_exit)
  24.     call    _syscall    ;call kernel
  25.  
  26.                 ;we do not return from sys_exit,
  27.                 ;there's no need to clean stack
  28. section .data
  29.  
  30. msg db  "Hello, world!",0xa ;our dear string
  31. len equ $ - msg         ;length of our dear string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement