; ------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello World"
; on a single line and then exits.
;
; To assemble to .obj: nasm -f win32 helloworld.asm
; To compile to .exe: gcc helloworld.obj -o helloworld.exe
; ------------------------------------------------------------------
global _main ; _start
; The data section is used for declaring initialized data or constants.
; This data does not change at runtime.
; You can declare various constant values, file names or buffer size etc. in this section.
section .data
msg db 0xA, 'Hello World!', 0xA, 0 ; Hello World message.
; 0xA (10) is hex for (NL), carriage return
; 0 terminates the line
msglen equ $ - msg ; length of the Hello World message.
mydate dw "06-Jan-2024 07:55 AM", 0xA ; Today's Date.
mydatelen equ $ - mydate ; Length of mydate variable.
s2 times 9 db '*' ; print '*' 9 times
; The bss section is used for declaring variables.
section .bss
; The text section is used for keeping the actual code.
; This section must begin with the declarationglobal main,
; which tells the kernel where the program execution begins.
section .text
; _start:
_main:
; print '*' 9 times.
mov edx, 9 ; message length
mov ecx, s2 ; message to write
mov ebx, 01h ; file descriptor (stdout)
mov eax, 04h ; system call number (sys_write)
int 0x80 ; call kernel
; Print message "Hello World".
mov edx, msglen ; message length
mov ecx, msg ; message to write
mov ebx, 01h ; file descriptor (stdout)
mov eax, 04h ; system call number (sys_write)
int 0x80 ; call kernel
; Print current system date.
mov edx, mydatelen ; message length
mov ecx, mydate ; message to write
mov ebx, 01h ; file descriptor (stdout)
mov eax, 04h ; system call number (sys_write)
int 0x80 ; call kernel
; print '*' 9 times.
mov edx, 9 ; message length
mov ecx, s2 ; message to write
mov ebx, 01h ; file descriptor (stdout)
mov eax, 04h ; system call number (sys_write)
int 0x80 ; call kernel
jmp exit
exit:
mov eax, 01h ; exit()
xor ebx, ebx ; errno
int 80h
OyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KOyBoZWxsb3dvcmxkLmFzbQo7CjsgVGhpcyBpcyBhIFdpbjMyIGNvbnNvbGUgcHJvZ3Jh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