fork download
  1. ; ------------------------------------------------------------------
  2. ; helloworld.asm
  3. ;
  4. ; This is a Win32 console program that writes "Hello World"
  5. ; on a single line and then exits.
  6. ;
  7. ; To assemble to .obj: nasm -f win32 helloworld.asm
  8. ; To compile to .exe: gcc helloworld.obj -o helloworld.exe
  9. ; ------------------------------------------------------------------
  10.  
  11. global _main ; _start
  12.  
  13. ; The data section is used for declaring initialized data or constants.
  14. ; This data does not change at runtime.
  15. ; You can declare various constant values, file names or buffer size etc. in this section.
  16. section .data
  17. msg db 0xA, 'Hello World!', 0xA, 0 ; Hello World message.
  18. ; 0xA (10) is hex for (NL), carriage return
  19. ; 0 terminates the line
  20. msglen equ $ - msg ; length of the Hello World message.
  21.  
  22. mydate dw "06-Jan-2024 07:55 AM", 0xA ; Today's Date.
  23. mydatelen equ $ - mydate ; Length of mydate variable.
  24.  
  25. s2 times 9 db '*' ; print '*' 9 times
  26.  
  27. ; The bss section is used for declaring variables.
  28. section .bss
  29.  
  30.  
  31. ; The text section is used for keeping the actual code.
  32. ; This section must begin with the declarationglobal main,
  33. ; which tells the kernel where the program execution begins.
  34. section .text
  35.  
  36. ; _start:
  37. _main:
  38. ; print '*' 9 times.
  39. mov edx, 9 ; message length
  40. mov ecx, s2 ; message to write
  41. mov ebx, 01h ; file descriptor (stdout)
  42. mov eax, 04h ; system call number (sys_write)
  43. int 0x80 ; call kernel
  44.  
  45. ; Print message "Hello World".
  46. mov edx, msglen ; message length
  47. mov ecx, msg ; message to write
  48. mov ebx, 01h ; file descriptor (stdout)
  49. mov eax, 04h ; system call number (sys_write)
  50. int 0x80 ; call kernel
  51.  
  52. ; Print current system date.
  53. mov edx, mydatelen ; message length
  54. mov ecx, mydate ; message to write
  55. mov ebx, 01h ; file descriptor (stdout)
  56. mov eax, 04h ; system call number (sys_write)
  57. int 0x80 ; call kernel
  58.  
  59. ; print '*' 9 times.
  60. mov edx, 9 ; message length
  61. mov ecx, s2 ; message to write
  62. mov ebx, 01h ; file descriptor (stdout)
  63. mov eax, 04h ; system call number (sys_write)
  64. int 0x80 ; call kernel
  65.  
  66. jmp exit
  67.  
  68. exit:
  69. mov eax, 01h ; exit()
  70. xor ebx, ebx ; errno
  71. int 80h
  72.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
*********
Hello World!
06-Jan-2024 07:55 AM
*********