我剛剛開始在win32上學習一些x86程序集,並且我已經使用ide for .asm文件附帶的自定義構建規則在Visual Studio 2008中使用了masm。我一直在嘗試使用DOS中斷打印到控制檯,但是我收到消息:「ASMTest.exe中0x00401004處未處理的異常:0xC0000005:訪問衝突讀取位置0xffffffff。」在第八行。我試圖輸出單個ASCII字符「A」(41H)這裏是MASM代碼:DOS中斷masm x86程序集崩潰
.386
.MODEL flat, stdcall
.CODE
start:
mov dl, 41h
mov ah, 2
int 21h
ret
end start
當我使用Debug.exe將,並用「A」命令輸入所有.CODE指令,並運行它('g'),它工作正常。
任何人都可以啓發我如何正確使用DOS中斷嗎?謝謝!
編輯:當在win32上編程時,Managu是正確的,你應該使用像WriteConsoleA的Windows API調用,而不是使用DOS中斷。 This是一個有用的資源。如果有人正在尋找的代碼來做到這一點(像我),那就是:
.386
.MODEL flat, stdcall
; Windows API prototypes
GetStdHandle proto :dword
WriteConsoleA proto :dword, :dword, :dword, :dword, :dword
ExitProcess proto :dword
STD_OUTPUT_HANDLE equ -11
.DATA
HelloWorldString db "hello, world", 10, 0
.CODE
strlen proc asciiData:dword
; EAX used as count, EBX as ascii char pointer, EDX (DL) as ascii char
mov eax, -1
mov ebx, asciiData
mov edx, 0
BeginLoop:
inc eax ; ++count (init is -1)
mov dl, [ebx] ; *dl = *asciiptr
inc ebx ; ++asciiptr
cmp dl, 0 ; if (*dl == '\0')
jne BeginLoop ; Goto the beginning of loop
ret
strlen endp
main proc
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov ecx, eax
invoke strlen, addr HelloWorldString
invoke WriteConsoleA, ecx, addr HelloWorldString, eax, 0, 0
ret
main endp
end
,這是因爲你的「RET的(設置的入口點主)
@unknown:你甚至告訴MASM爲您創造一個32位可執行文件('.MODEL flat') – 2009-09-12 05:19:32