gcc不推(装配推)args,即使:
-mpush-args -mno-accumulate-outgoing-args -mno-stack-arg-probe
但也没有任何错误。
我尝试了2种不同版本的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"
NASM类型汇编:
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