I'm starting NASM Assembler after finishing FASM. I'm coding this in a Windows Operating System. My code reads:
section.data ;Constant
msg: db "Hello World!"
msg_L: equ $-msg ; Current - msg1
section.bss ;Varialble
section.text ; Code
global _WinMain@16
_WinMain@16:
mov eax,4
mov ebx,1; Where to wrte it out. Terminal
mov ecx, msg
mov edx, msg_L
int 80h
mov eax, 1 ; EXIT COMMAND
mov ebx,0 ; No Eror
int 80h
To compile it and execute I use:
nasm -f win32 test.asm -o test.o
ld test.o -o test.exe
I am currently following this video on tutorials on NASM. I changed the start to WIN32, but when I execute it, it just gets stuck and won't run... Any problems with this?
INT is the assembly mnemonic for "interrupt". The code after it specifies the interrupt code. (80h/0x80 or 128 in decimal is the Unix System Call interrupt) When running in Real Mode (16-bit on a 32-bit chip), interrupts are handled by the BIOS.
You are trying to make a Linux system call (int 80h
) on the Windows operating system.
This will not work. You need to call Windows API functions. For example, MessageBox
will display a message box on the screen.
section .rdata ; read-only Constant data
msg: db "Hello World!"
msg_L: equ $-msg ; Current - msg1
section .text ; Code
global _WinMain@16
extern _MessageBoxA@16
_WinMain@16:
; Display a message box
push 40h ; information icon
push 0
push msg
push 0
call _MessageBoxA@16
; End the program
xor eax, eax
ret
Make sure that the book/tutorial you're reading is about Windows programming with NASM, not Linux programming!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With