.text usage: .string "try to write : ./main test \n" err_fork: .string "fork" some_text: .string "%s qwertyuiop asdfghjkl zxcvbnm \n" file_cat: .string "/bin/cat" cat_arg0: .string "cat" err_execv: .string "execv" wait_text: .string "wait" .globl main .text main: # 0(%ebp) int ebp # 4(%ebp) ret # 8(%ebp) int argc # 12(%ebp) char** argv pushl %ebp movl %esp, %ebp #check argc cmp $2, 8(%ebp) jge argc_ok movl 12(%ebp), %ebx pushl $usage call printf addl $8, %esp #exit jmp exit_fail argc_ok: #fork call fork testl %eax, %eax #sravnivaem eax s nulem, esli eax<0, to "-" #esli eax = 0 to zero flag ustanovitsya #Intel Optimization Manual jns fork_success #perror pushl $err_fork call perror #ob"yasnyet kodi oshibok addl $4, %esp jmp exit_fail fork_success: jnz parent movl 8(%ebp), %eax shl $4, %eax pushl %eax pushl 12(%ebp) pushl %ebp call memcpy addl $12, %esp #child process #execv(file_cat, argv) movl $cat_arg0, (%eax) pushl %eax pushl $file_cat call execv #zamenyaet process programmoi iz file #zamenyetsya cat addl $8, %esp #perror pushl err_execv call perror addl $4, %esp #exit pushl $1 call exit parent: #parent process pushl $0 call wait addl $4, %esp testl %eax, %eax js wait_err #roditel dolzhen vizvat printf(3) i raspechatat kakoi libo text pushl $some_text call printf addl $4, %esp #exit pushl $0 call exit wait_err: pushl $wait_text call perror addl $4, %esp pushl $1 call exit exit_fail: #exit pushl $1 call exit