//---------------------------------------------------------------- // execdemo.s // // This program repeatedly forks a child-process which then // executes our previously developed 'showpid' application. // (That program must be in the current working directory.) // // assembly using: $ as execdemo.s -o execdemo.o // and link using: $ ld execdemo.o -o execdemo // // programmer: ALLAN CRUSE // written on: 21 FEB 2007 //---------------------------------------------------------------- .equ sys_exit, 1 # system-call ID-number .equ sys_fork, 2 # system-call ID-number .equ sys_exec, 11 # system-call ID-number .equ sys_waitpid, 7 # system-call ID-number .section .data appname: .asciz "showpid" # null-terminated string theargs: .long appname, 0 # argument-list for exec counter: .long 6 # number of repetitions .section .text _start: # fork a child process movl $sys_fork, %eax # setup service ID-number int $0x80 # invoke kernel service orl %eax, %eax # process is the parent? jz child # no, skip ahead to child # parent waits for child movl $sys_waitpid, %ebx # setup service ID-number xchg %eax, %ebx # specify PID of child xorl %ecx, %ecx # ignore exit-status xorl %edx, %edx # no waitpid options int $0x80 # invoke kernel service decl counter # decrement loop-counter jnz _start # again unless exhausted jmp quit # else terminate parent child: # execute the named application movl $sys_exec, %eax # setup service ID-number leal appname, %ebx # specify the application leal theargs, %ecx # point to arguments list xorl %edx, %edx # keep current enironment int $0x80 # invoke kernel service quit: # terminate this application movl $sys_exit, %eax # setup service ID-number xorl %ebx, %ebx # specify exit-code value int $0x80 # invoke kernel service .global _start # make entry-point visible .end # nothing more to assemble