问题描述
在.asm文件中,我想调用crt_printf进行打印(或调用ExitProcess结束主过程).但是我的代码附带:
in .asm file, I'd like to call crt_printf to print (or call ExitProcess to end main procedure). However my code goes with:
.386
.model flat,stdcall
option casemap:none
includelib D:\masm32\lib\msvcrt.lib
printf proto C:dword,:vararg
scanf proto C:dword,:vararg
.DATA
print_int DB "%d",0
print_char DB "%c",0
我的呼叫过程与:
PUSH offset __temp13@_cal@main
PUSH offset print_string
CALL crt_printf
ADD ESP, 8
PUSH _realCock@main
PUSH offset print_int
CALL crt_printf
ADD ESP, 8
PUSH offset __temp14@_cal@main
当我点击全部构建的按钮时,消息随之出现:
When I Click the button of build All, messages come with:
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: D:\masm32\bin\object_code.asm
D:\masm32\bin\object_code.asm(105) : error A2006: undefined symbol : crt_printf
D:\masm32\bin\object_code.asm(109) : error A2006: undefined symbol : crt_printf
D:\masm32\bin\object_code.asm(179) : error A2006: undefined symbol : crt_scanf
D:\masm32\bin\object_code.asm(249) : error A2006: undefined symbol : ExitProcess
Assembly Error
我已经为这样的错误苦苦挣扎了24小时,Thx!
I've struggled with such error for 24 hours, Thx!
推荐答案
crt_printf
是MASM32开发人员的一种特殊构造,可将其与他们的宏 printf区别开
.如果您不包括 \ masm32 \ macros \ macros.asm
,则不需要此特殊功能:
crt_printf
is a special construct of the MASM32 developers to distiguish it from their macro printf
. If you don't include \masm32\macros\macros.asm
you don't need this special feature:
.386
.model flat,stdcall
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\kernel32.lib
printf proto C :dword, :vararg ; msvcrt
ExitProcess proto STDCALL :DWORD ; kernel32
.DATA
fmt db "%s",10,0
hello db "Hello world!",0
.CODE
main PROC
push OFFSET hello
push OFFSET fmt
call printf
add esp, (2 * 4)
push 0
call ExitProcess
main ENDP
END main
crt _...
别名在 msvcrt.inc
中声明:
.386
.model flat,stdcall
include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\kernel32.lib
printf proto C :dword, :vararg ; msvcrt
ExitProcess proto STDCALL :DWORD ; kernel32
.DATA
fmt db "%s",10,0
hello db "Hello world!",0
.CODE
main PROC
push OFFSET hello
push OFFSET fmt
call crt_printf
add esp, (2 * 4)
push 0
call ExitProcess
main ENDP
END main
如果您希望包含所有声明和宏的全部内容,则包括 masm32rt.inc
:
If you want the whole bunch with all declarations and macros then include masm32rt.inc
:
include \masm32\include\masm32rt.inc
.DATA
fmt db "%s",10,0
hello db "Hello world!",0
.CODE
main PROC
push OFFSET hello
push OFFSET fmt
call crt_printf
add esp, (2 * 4)
printf ("Hello again: %s\n",OFFSET hello);
push 0
call ExitProcess
main ENDP
END main
这篇关于具有lib的MASM32中的crt_printf和ExitProcess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!