Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; This program runs in 32-bit protected mode.
  3. ;  build: nasm -f elf -F stabs name.asm
  4. ;  link:  ld -o name name.o
  5. ;
  6. ; In 64-bit protected mode you can use 64-bit registers (e.g. rax instead of eax, rbx instead of ebx, etc..)
  7. ; Also change "-f elf " for "-f elf64" in build command.
  8. ;
  9. section .data                           ; section for initialized data
  10. str:     db 'Hello world!', 0Ah         ; message string with new-line char at the end (10 decimal)
  11. str_len: equ $ - str                    ; calcs length of string (bytes) by subtracting this' address ($ symbol) from the str's start address
  12.  
  13. section .text                           ; this is the code section
  14. global _start                           ; _start is the entry point and needs global scope to be 'seen' by the linker -equivalent to main() in C/C++
  15. _start:                                 ; procedure start
  16.         mov    eax, 4                   ; specify the sys_write function code (from OS vector table)
  17.         mov    ebx, 1                   ; specify file descriptor stdout -in linux, everything's treated as a file, even hardware devices
  18.         mov    ecx, str                 ; move start _address_ of string message to ecx register
  19.         mov    edx, str_len             ; move length of message (in bytes)
  20.         int    80h                      ; tell kernel to perform the system call we just set up - in linux services are requested through the kernel
  21.         mov    eax, 1                   ; specify sys_exit function code (from OS vector table)
  22.         mov    ebx, 0                   ; specify return code for OS (0 = everything's fine)
  23.         int    80h                      ; tell kernel to perform system call
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement