; ------------------------------------------------------------------
; 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
