剛剛閱讀了很多教程,並認爲我會在Windows上嘗試使用NASM。我嘗試了幾個簡單的「Hello World」版本,其中一個應該使用_printf函數將文本輸出到stdout。Win32 NASM HelloWorld在AccessViolation中使用Prinft結果
下面的代碼:
; Build by doing:
; nasm -f win32 -o test.o test.asm
; link /SUBSYSTEM:CONSOLE libcmt.lib test.o
section .text
global _start
extern _printf
_start:
push msg ; Push msg on stack
call _printf ; Call printf
add esp, 4 ; Reset the stack
; return 0
xor eax, eax
ret
; Our string, null terminated
msg: db "Hello World ", 13,10,0
我建立它使用 「NASM -f win32的-o test.o TEST.ASM」 描述,並與微軟的Visual Studio 2013的接頭連接它。目前爲止工作良好,但只要我嘗試運行可執行文件,就會遇到訪問衝突。使用精確鏈接器命令:
link /subsystem:console /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib" /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib" /nodefaultlib /entry:start test.o libcmt.lib kernel32.lib
我盡力用OllyDbg中去的錯誤,但這並沒有幫助。也許有人在這裏有一個想法?...
問候
裝配看起來沒問題。到底你是如何將它與Visual Studio 2013連接起來的? – lurker 2015-03-19 09:58:59
確切的命令是:link/subsystem:console/LIBPATH:「C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ VC \ lib」/ LIBPATH:「C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Lib「/ nodefaultlib/entry:start test.o libcmt.lib kernel32.lib – inzanez 2015-03-19 10:12:21
一般來說,要使用C庫,應該命名入口點'main'並讓C運行庫啓動進程並然後調用你的'main'。 – Jester 2015-03-19 13:37:20