.code32
.text
.globl _start
_start:
; .globl main
.extern printf
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl 8(%ebp), %eax
movl 12(%ebp), %ebx
movl $0, %ecx
pushl %eax
pushl $msg2
call printf
add $8, %esp
movl %ebp, %esp
popl %ebp
movl $1, %eax
movl $0, %ebx
int $0x80
.data
; .asciz "Arg = %s"
msg2: .asciz "Arg Count = %d"
假设参数的数量比基本指针高8个字节,我将进入eax,然后在消息之前将eax推入堆栈,然后调用printf。但是,在编译和链接之后,该程序只运行并退出而不向屏幕打印任何内容。为什么这样做?
像这样组装和链接:
as --32 select.s -o main.o
ld -m elf_i386 -I/lib/ld-linux.so.2 -lc main.o -o main