问题
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?
回答1:
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!
来源:https://stackoverflow.com/questions/38269269/nasm-tutorial-uses-int-80h-but-this-isnt-working-on-windows