//---------------------------------------------------------------- // execdemo.s // // This program repeatedly forks a child-process which then // executes our 'stackseg' application to show the size and // memory-range of that child's stack-region. // // assembly using: $ as execdemo.s -o execdemo.o // and link using: $ ld execdemo.o -o execdemo // // programmer: ALLAN CRUSE // written on: 19 FEB 2006 //---------------------------------------------------------------- .equ sys_exit, 1 .equ sys_fork, 2 .equ sys_exec, 11 .equ sys_waitpid, 7 .section .data appname: .asciz "stackseg" theargs: .long appname, 0 counter: .long 24 .section .text _start: # fork a child process movl $sys_fork, %eax int $0x80 orl %eax, %eax jz 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 .end