NASM 教程使用 int 80h,但这不适用于 Windows
NASM tutorial uses int 80h, but this isn't working on Windows
我在完成 FASM 后开始 NASM 汇编程序。我正在 Windows 操作系统中对此进行编码。
我的代码是:
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
要编译并执行我使用:
nasm -f win32 test.asm -o test.o
ld test.o -o test.exe
我目前正在关注 NASM 上的教程视频。我把启动改成了WIN32,但是当我执行的时候,它就卡住了,不会运行...这个有什么问题吗?
您正在尝试在 Windows 操作系统上进行 Linux 系统调用 (int 80h
)。
这行不通。您需要调用 Windows API 函数。例如,MessageBox
将在屏幕上显示一个消息框。
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
确保您正在阅读的 book/tutorial 是关于 Windows 使用 NASM 编程的,而不是 Linux 编程!
我在完成 FASM 后开始 NASM 汇编程序。我正在 Windows 操作系统中对此进行编码。 我的代码是:
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
要编译并执行我使用:
nasm -f win32 test.asm -o test.o
ld test.o -o test.exe
我目前正在关注 NASM 上的教程视频。我把启动改成了WIN32,但是当我执行的时候,它就卡住了,不会运行...这个有什么问题吗?
您正在尝试在 Windows 操作系统上进行 Linux 系统调用 (int 80h
)。
这行不通。您需要调用 Windows API 函数。例如,MessageBox
将在屏幕上显示一个消息框。
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
确保您正在阅读的 book/tutorial 是关于 Windows 使用 NASM 编程的,而不是 Linux 编程!