示例:
Dim x As Integer, y As Integer
Input "x=", x
y = x ^ 3 + 3 * x ^ 2 - 24 * x + 30
Print y
End当我使用FreeBasic编译器生成这个源代码的汇编代码时,我发现
.globl _main
_main:和
call ___main在汇编代码中。此外,看起来输入语句被编译为
call _fb_ConsoleInput@12和
call _fb_InputInt@4"^“运算符编译为
call _pow(我不确定FreeBasic的数学函数库是集成的还是外部的)
而Print语句编译为
call _fb_PrintInt@12而End语句编译为
call _fb_End@4问题是: FreeBasic源代码是如何编译的?为什么_main和___main出现在汇编代码中?I/O语句是否编译为函数调用?
参考:由FreeBasic编译器生成的程序集代码
.intel_syntax noprefix
.section .text
.balign 16
.globl _main
_main:
push ebp
mov ebp, esp
and esp, 0xFFFFFFF0
sub esp, 20
mov dword ptr [ebp-4], 0
call ___main
push 0
push dword ptr [ebp+12]
push dword ptr [ebp+8]
call _fb_Init@12
.L_0002:
mov dword ptr [ebp-8], 0
mov dword ptr [ebp-12], 0
push -1
push 0
push 2
push offset _Lt_0004
call _fb_StrAllocTempDescZEx@8
push eax
call _fb_ConsoleInput@12
lea eax, [ebp-8]
push eax
call _fb_InputInt@4
push dword ptr [_Lt_0005+4]
push dword ptr [_Lt_0005]
fild dword ptr [ebp-8]
sub esp,8
fstp qword ptr [esp]
call _pow
add esp, 16
fild dword ptr [ebp-8]
fild dword ptr [ebp-8]
fxch st(1)
fmulp
fmul qword ptr [_Lt_0005]
fxch st(1)
faddp
mov eax, dword ptr [ebp-8]
imul eax, 24
push eax
fild dword ptr [esp]
add esp, 4
fxch st(1)
fsubrp
fadd qword ptr [_Lt_0006]
fistp dword ptr [ebp-12]
push 1
push dword ptr [ebp-12]
push 0
call _fb_PrintInt@12
push 0
call _fb_End@4
.L_0003:
push 0
call _fb_End@4
mov eax, dword ptr [ebp-4]
mov esp, ebp
pop ebp
ret
.section .data
.balign 4
_Lt_0004: .ascii "x=\0"
.balign 8
_Lt_0005: .quad 0x4008000000000000
.balign 8
_Lt_0006: .quad 0x403E000000000000发布于 2022-06-22 09:55:03
是的,像PRINT这样的东西是作为函数调用实现的,不过我不知道为什么这对您很重要,除非您目前正在学习程序集。
至于_main,这是main() C函数作为主程序的ASM名称。在x86上,C中的全局/导出函数名通常在_输出前加上_。
___main是由MinGW C运行时库启动代码调用的MinGW C函数的ASM名称,然后执行_main中的任何内容。同样,您将看到C函数名称前面的额外_。
然后调用fb_Init(argc, argv, FB_LANG_FB),用参数向量argv中默认的"fb“FreeBASIC方言和argc元素初始化FreeBASIC运行时库。@12意味着参数列表有12个字节长(例如,4+4+4=12和fb_Init一样);有关这方面的更多信息,请参见stdcall Docs。
https://stackoverflow.com/questions/72298072
复制相似问题