Assembly tutorial for beginners


SUBMITTED BY: hegias

DATE: Oct. 7, 2015, 11:01 p.m.

FORMAT: NASM

SIZE: 1.8 kB

HITS: 793

  1. ;=================================================================
  2. ; SYSCALLS
  3. ; see system functions: /usr/include/asm/unistd_32.h
  4. ; see arguments: man 2 <cmd>
  5. ;=================================================================
  6. ; COMPILATION
  7. ; compiler: nasm -f elf hello.asm
  8. ; linker: ld -s -o hello hello.o
  9. ;=================================================================
  10. ; REGISTERS
  11. ; xtended 32b: eax, ebx, ecx, edx
  12. ; float: st0, st1
  13. ;=================================================================
  14. ; SIZES
  15. ; b: byte (8 bits)
  16. ; w: word (16 bits)
  17. ; dw: dword (32 bits)
  18. ; q: quadwords (64 bits)
  19. ;=================================================================
  20. ; SPECIAL
  21. ; $: end of variable address
  22. ;=================================================================
  23. ; ARGUMENTS
  24. ; use :eax, ebx, ecx, edx, esi, edi, ebp
  25. ; or: eax et ebx contient l'adresse de la liste
  26. ; input args: found in eax (nb args),
  27. ; ebx (program name ie arg 0), ecx (arg 1)
  28. section .data
  29. msg: db 'hello world',10 ; declare msg
  30. msgLen: equ $-msg
  31. section .bss
  32. ; variables, reserving memory
  33. section .text
  34. global _start
  35. _start:
  36. ;kernel write
  37. mov eax,4 ; arg 1: syscall write id
  38. mov ebx,1 ; arg 2: file descriptor (standard output)
  39. mov ecx,msg ; arg 3: msg location
  40. mov edx,msgLen ; arg 4: msg length
  41. int 80h ; kernel call
  42. ;kernel exit
  43. mov eax,1 ; argument 1: syscall 'exit' id
  44. mov ebx,0 ; argument 2: exit code 0
  45. int 80h ; kernel call

comments powered by Disqus