【发布时间】:2015-08-23 21:03:29
【问题描述】:
我的问题是:当我尝试执行在 NASM 和 Windows 8 64 位中组装的 .exe 时,告诉我这个 .exe 与 64 位不兼容。那么,我应该如何组装这段代码(我是从网上获得的)?
使用的代码
STD_OUTPUT_HANDLE equ -11
STD_INPUT_HANDLE equ -10
NULL equ 0
global start
extern ExitProcess, GetStdHandle, WriteConsoleA, ReadConsoleInputA
section .data ;message we want to display on console
msg db "Press a key to continue...", 13, 10, 0
msg.len equ $ - msg
consoleInHandle dd 1
section .bss ;buffers declaration
buffer_out resd 2
buffer_in resb 32
section .text
start: ;starting point of our program
push STD_OUTPUT_HANDLE
call GetStdHandle ;call to get a handle to the
push NULL ;specified mode (input, output...)
push buffer_out
push msg.len
push msg
push eax ;contains the GetStdHandle result
call WriteConsoleA ;call to print our msg in console
read:
push STD_INPUT_HANDLE
call GetStdHandle ;new call to get input handle
push NULL
push 1
push buffer_in
push eax
call ReadConsoleInputA ;call to detect user input
;this function will wait til
exit: ;it detects enough keypresses
push NULL ;(in this case, 1)
call ExitProcess
用于组装的命令: nasm -fwin32 main.asm -o main.exe
【问题讨论】:
-
您生成的是 Microsoft Win32 对象文件。您必须使用链接器从该目标文件生成可执行文件。
标签: windows assembly console-application nasm