lnxhello.asm 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;Testname=aout; Arguments=-faout -olnxhello.o -Ox; Files=stdout stderr lnxhello.o
  2. ;Testname=aoutb; Arguments=-faoutb -olnxhello.o -Ox; Files=stdout stderr lnxhello.o
  3. ;Testname=as86; Arguments=-fas86 -olnxhello.o -Ox; Files=stdout stderr lnxhello.o
  4. ;Testname=elf32; Arguments=-felf32 -olnxhello.o -Ox; Files=stdout stderr lnxhello.o
  5. ;
  6. ; Assembly "Hello, World!" for Linux
  7. ;
  8. ; Properly defined in <sys/syscall.h>
  9. %define SYS_exit 1
  10. %define SYS_write 4
  11. section .text
  12. global _start
  13. _start:
  14. ; gdb doesn't like to stop at the entry point address, so
  15. ; we put a nop here for pure convenience
  16. nop
  17. write_hello:
  18. mov edx, hello_len
  19. mov ecx, hello
  20. .loop:
  21. mov eax, SYS_write
  22. mov ebx, 1 ; stdout
  23. int 80h
  24. cmp eax, -4096
  25. ja error
  26. add ecx, eax
  27. sub edx, eax
  28. jnz .loop
  29. ok:
  30. mov eax, SYS_exit
  31. xor ebx, ebx
  32. int 80h
  33. hlt
  34. error:
  35. mov eax, SYS_exit
  36. mov ebx, 1 ; Error
  37. int 80h
  38. hlt
  39. section .rodata
  40. hello: db "Hello, World!", 10
  41. hello_len equ $-hello