Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么我';我从教程中得到了不同的结果_C_Assembly_Gcc_X86 - Fatal编程技术网

C 为什么我';我从教程中得到了不同的结果

C 为什么我';我从教程中得到了不同的结果,c,assembly,gcc,x86,C,Assembly,Gcc,X86,我学习了一个教程,里面有一个c代码 void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } void main() { function(1,2,3); } pushl $3 pushl $2 pushl $1 call function 他说,在使用gcc和-S开关编译这段代码之后,我们将得到这样的汇编结果 void function(int a, int b, int c) {

我学习了一个教程,里面有一个c代码

void function(int a, int b, int c) {
   char buffer1[5];
   char buffer2[10];
}

void main() {
   function(1,2,3);
}
pushl $3
pushl $2
pushl $1
call function
他说,在使用gcc和-S开关编译这段代码之后,我们将得到这样的汇编结果

void function(int a, int b, int c) {
   char buffer1[5];
   char buffer2[10];
}

void main() {
   function(1,2,3);
}
pushl $3
pushl $2
pushl $1
call function
然而,当我编译它时,我的主要部分看起来像

main:
.LFB1:
.cfi_startproc
endbr64
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq    %rsp, %rbp
.cfi_def_cfa_register 6
movl    $3, %edx
movl    $2, %esi
movl    $1, %edi
call    function
nop
popq    %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc

两者的意思是相同的还是我在某个地方做错了?

您编译的是64位,而教程是32位。使用
gcc-m32
。即使这样,也不能保证您将获得相同的输出。没有理由期望任何两个编译器、同一编译器的任何版本、编译器的所有不同命令行选项,生成与任何其他组合相同的输出。唯一的期望是输出是高级语言的功能等价物。相关:re:让GCC简化其asm输出以匹配旧教程(默认情况下是从
-fpie
之前,以及在16字节堆栈对齐之前,等等)