我刚刚开始在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