Visual studio 为什么printf是在本地定义的,而getchar是在外部定义的?
将汇编语言与MASM(x86体系结构)结合使用时,可以通过包含库来使用标准C函数。例如:Visual studio 为什么printf是在本地定义的,而getchar是在外部定义的?,visual-studio,assembly,x86,masm,Visual Studio,Assembly,X86,Masm,将汇编语言与MASM(x86体系结构)结合使用时,可以通过包含库来使用标准C函数。例如:printf和getchar 在visualstudio中使用Asembly with Source code/FAs编译并检查生成的程序集文件时,我偶然发现了以下几点: PUBLIC _printf EXTRN __imp__getchar : PROC \u printf声明为PUBLIC并在本地定义(内联在同一文件中,因此未在库文件中外部定义),而\u imp\u getchar在外部定义 这是
printf
和getchar
在visualstudio
中使用Asembly with Source code/FAs
编译并检查生成的程序集文件时,我偶然发现了以下几点:
PUBLIC _printf
EXTRN __imp__getchar : PROC
\u printf
声明为PUBLIC
并在本地定义(内联在同一文件中,因此未在库文件中外部定义),而\u imp\u getchar
在外部定义
这是编译器在debug
中编译时生成的结果\u printf
定义:
_TEXT SEGMENT
__ArgList$ = -20 ; size = 4
__Result$ = -8 ; size = 4
__Format$ = 8 ; size = 4
_printf PROC ; COMDAT
; 950 : {
push ebp
mov ebp, esp
sub esp, 216 ; 000000d8H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-216]
mov ecx, 54 ; 00000036H
mov eax, -858993460 ; ccccccccH
rep stosd
; 951 : int _Result;
; 952 : va_list _ArgList;
; 953 : __crt_va_start(_ArgList, _Format);
call ??$__vcrt_va_start_verify_argument_type@QBD@@YAXXZ ; __vcrt_va_start_verify_argument_type<char const * const>
lea eax, DWORD PTR __Format$[ebp+4]
mov DWORD PTR __ArgList$[ebp], eax
; 954 : _Result = _vfprintf_l(stdout, _Format, NULL, _ArgList);
mov eax, DWORD PTR __ArgList$[ebp]
push eax
push 0
mov ecx, DWORD PTR __Format$[ebp]
push ecx
mov esi, esp
push 1
call DWORD PTR __imp____acrt_iob_func
add esp, 4
cmp esi, esp
call __RTC_CheckEsp
push eax
call __vfprintf_l
add esp, 16 ; 00000010H
mov DWORD PTR __Result$[ebp], eax
; 955 : __crt_va_end(_ArgList);
mov DWORD PTR __ArgList$[ebp], 0
; 956 : return _Result;
mov eax, DWORD PTR __Result$[ebp]
; 957 : }
pop edi
pop esi
pop ebx
add esp, 216 ; 000000d8H
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
_printf ENDP
_TEXT ENDS
\u文本段
__ArgList$=-20;尺寸=4
__结果$=-8;尺寸=4
__格式$=8;尺寸=4
_printfproc;COMDAT
; 950 : {
推ebp
电动汽车
子esp,216;000000 D8H
推ebx
推动esi
推式电子数据交换
lea edi,DWORD PTR[ebp-216]
mov ecx,54;000000 36小时
mov eax,-858993460;CCC H
雷普斯托德
;951:整数结果;
;952:va_列表_ArgList;
;953:uu crt_va_start(_ArgList,_格式);
调用???$\uuu vcrt\u va\u start\u verify\u参数_type@QBD@@YAXXZ;\uuuuvcrt\u va\u start\u verify\u argument\u type
lea eax,DWORD PTR\uu格式$[ebp+4]
mov DWORD PTR__参数列表$[ebp],eax
;954:_Result=_vfprintf_l(标准输出,_格式,NULL,_参数列表);
mov eax,DWORD PTR__ArgList$[ebp]
推送eax
推0
mov ecx,DWORD PTR__格式$[ebp]
推ecx
电影
推1
呼叫DWORD PTR\uuuuuuuuuuuuuuuuuuuuuu acrt\u iob\u func
添加esp,4
cmp esi,esp
呼叫RTC检查ESP
推送eax
调用
添加esp,16;000000 10h
mov DWORD PTR_uuu结果$[ebp],eax
;955:u crt_va_end(_ArgList);
mov DWORD PTR__ArgList$[ebp],0
;956:返回_结果;
mov eax,DWORD PTR\uuu结果$[ebp]
; 957 : }
流行电子数据交换
波普esi
流行电子束
增加esp,216;000000 D8H
电子稳定程序
呼叫RTC检查ESP
电除尘器
流行ebp
ret 0
_printf-ENDP
_文本结尾
我的问题
为什么
\u printf
是本地定义的,而不是外部定义的getchar
。printf的代码就在您的列表中。如果卸下部件,将获得:
; 950 : {
; 951 : int _Result;
; 952 : va_list _ArgList;
; 953 : __crt_va_start(_ArgList, _Format);
; 954 : _Result = _vfprintf_l(stdout, _Format, NULL, _ArgList);
; 955 : __crt_va_end(_ArgList);
; 956 : return _Result;
; 957 : }
因此,
printf
是一个调用\u vfprintf\u l
的(内联)函数,它完成了所有繁重的工作(可能还用于实现其他C库函数)。因为这是printf
本身的源代码。@Jester这是如何回答我的问题的?这如何解释getchar
的源代码没有被复制?