#argc.s 虽然写得乱七八糟的,但也算是第一个有点样子的汇编程序:
.data
fmt: .string "There are %d parameters:\n"
str: .string "================== shell =================\n"
flag: .int 0
.text
.globl _start
_start:
movl (%esp), %ecx
pushl %ecx
pushl $fmt
call printf
addl $8, %esp
movl %esp, %ecx
s:
addl $4, %ecx
pushl %ecx
_loop_print_argv:
pushl (%ecx)
call puts
addl $4, %esp
popl %ecx
addl $4, %ecx
pushl %ecx
cmpl $0, (%ecx)
je shell_var
jmp _loop_print_argv
shell_var:
movl flag, %eax
cmpl $0, %eax
jne break
addl $1, %eax
movl %eax, flag
pushl $str
call puts
addl $4, %esp
popl %ecx
jmp s
break:
movl $1, %eax
movl $0, %ebx
int $0x80
#------------------------------