GCC不推送参数,即使使用-mpush args-mno累计传出args-mno堆栈arg探测

GCC不推送参数,即使使用-mpush args-mno累计传出args-mno堆栈arg探测,c,gcc,assembly,C,Gcc,Assembly,gcc不推送(程序集推送)参数,即使使用: -mpush args-mno累计传出args-mno堆栈arg探测 但也没有任何错误 我用两个不同版本的gcc进行了尝试。 我需要做什么 编辑:我试图构建一个简单的内核 char read_char(void) { return 'A'; //Doesn't read any char, just return 'A'. } void print(char letter,char row,char col){ char*VGA=(ch

gcc不推送(程序集推送)参数,即使使用:
-mpush args-mno累计传出args-mno堆栈arg探测

但也没有任何错误

我用两个不同版本的gcc进行了尝试。
我需要做什么

编辑:我试图构建一个简单的内核

char read_char(void)
{
    return 'A'; //Doesn't read any char, just return 'A'.
}

void print(char letter,char row,char col){
   char*VGA=(char*) 0xB8000;
   VGA[(row*80+col)*2]=letter;
}

void __main(void){} \\ just for the linker (ld)
void main(void){
   print(read_char(),2,3);
}
但在大会上:

    .file   "test.c"
    .section    .text.unlikely,"x"
.LCOLDB0:
    .text
.LHOTB0:
    .p2align 4,,15
    .globl  read_char
    .def    read_char;  .scl    2;  .type   32; .endef
    .seh_proc   read_char
read_char:
    .seh_endprologue
    movl    $65, %eax
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE0:
    .text
.LHOTE0:
    .section    .text.unlikely,"x"
.LCOLDB1:
    .text
.LHOTB1:
    .p2align 4,,15
    .globl  print
    .def    print;  .scl    2;  .type   32; .endef
    .seh_proc   print
print:
    .seh_endprologue
    movsbl  %dl, %edx
    movsbl  %r8b, %r8d
    leal    (%rdx,%rdx,4), %eax
    sall    $4, %eax
    addl    %eax, %r8d
    addl    %r8d, %r8d
    movslq  %r8d, %r8
    movb    %cl, 753664(%r8)
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE1:
    .text
.LHOTE1:
    .section    .text.unlikely,"x"
.LCOLDB2:
    .text
.LHOTB2:
    .p2align 4,,15
    .globl  __main
    .def    __main; .scl    2;  .type   32; .endef
    .seh_proc   __main
__main:
    .seh_endprologue
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE2:
    .text
.LHOTE2:
    .def    __main; .scl    2;  .type   32; .endef
    .section    .text.unlikely,"x"
.LCOLDB3:
    .section    .text.startup,"x"
.LHOTB3:
    .p2align 4,,15
    .globl  main
    .def    main;   .scl    2;  .type   32; .endef
    .seh_proc   main
main:
    subq    $40, %rsp
    .seh_stackalloc 40
    .seh_endprologue
    call    __main
    movb    $65, 753990
    addq    $40, %rsp
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE3:
    .section    .text.startup,"x"
.LHOTE3:
    .ident  "GCC: (tdm64-1) 4.9.2"
main:
push   ebp
mov    ebp,esp

call read_char ;at eax the return

mov    eax,0x3 ;3rd arg the eax override! (have not the return of read_char anymore!)
mov    edx,0x2 ;2nd arg
mov    ecx,eax ;1st arg but here the gcc thinks the eax contains the return but the eax have been overridden!
call   print

pop ebp
ret
NASM型组件:

    .file   "test.c"
    .section    .text.unlikely,"x"
.LCOLDB0:
    .text
.LHOTB0:
    .p2align 4,,15
    .globl  read_char
    .def    read_char;  .scl    2;  .type   32; .endef
    .seh_proc   read_char
read_char:
    .seh_endprologue
    movl    $65, %eax
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE0:
    .text
.LHOTE0:
    .section    .text.unlikely,"x"
.LCOLDB1:
    .text
.LHOTB1:
    .p2align 4,,15
    .globl  print
    .def    print;  .scl    2;  .type   32; .endef
    .seh_proc   print
print:
    .seh_endprologue
    movsbl  %dl, %edx
    movsbl  %r8b, %r8d
    leal    (%rdx,%rdx,4), %eax
    sall    $4, %eax
    addl    %eax, %r8d
    addl    %r8d, %r8d
    movslq  %r8d, %r8
    movb    %cl, 753664(%r8)
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE1:
    .text
.LHOTE1:
    .section    .text.unlikely,"x"
.LCOLDB2:
    .text
.LHOTB2:
    .p2align 4,,15
    .globl  __main
    .def    __main; .scl    2;  .type   32; .endef
    .seh_proc   __main
__main:
    .seh_endprologue
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE2:
    .text
.LHOTE2:
    .def    __main; .scl    2;  .type   32; .endef
    .section    .text.unlikely,"x"
.LCOLDB3:
    .section    .text.startup,"x"
.LHOTB3:
    .p2align 4,,15
    .globl  main
    .def    main;   .scl    2;  .type   32; .endef
    .seh_proc   main
main:
    subq    $40, %rsp
    .seh_stackalloc 40
    .seh_endprologue
    call    __main
    movb    $65, 753990
    addq    $40, %rsp
    ret
    .seh_endproc
    .section    .text.unlikely,"x"
.LCOLDE3:
    .section    .text.startup,"x"
.LHOTE3:
    .ident  "GCC: (tdm64-1) 4.9.2"
main:
push   ebp
mov    ebp,esp

call read_char ;at eax the return

mov    eax,0x3 ;3rd arg the eax override! (have not the return of read_char anymore!)
mov    edx,0x2 ;2nd arg
mov    ecx,eax ;1st arg but here the gcc thinks the eax contains the return but the eax have been overridden!
call   print

pop ebp
ret

您尝试过在这些选项旁边启用优化(O1/O2)吗?没有,这是什么?我们只需尝试使用
-O2-mpush args-mno累计传出args-mno stack arg probe
。许多GCC标志需要启用的优化才能有效。不知道这里是否是这样,但值得一试。同时展示生成程序集输出的实际源代码,使用剪切和粘贴将其包含在帖子中,这样您就不会犯任何错误或遗漏任何内容。您还应该显示完整的命令以及编译源代码时使用的所有选项。您为我们提供了64位代码(而不是32位代码)。如果要编写32位内核,则需要使用
-m32
。您可能还需要使用
-独立式-nostinc
。我从输出中得知,您一定使用了某种类型的优化,因为这一行基本上满足了您的要求:
movb$65753990
。写了字母“a”的地址是0xB8146