//--------------------------------------------------------------- // showpid.s // // This example illustrates use of the 'getpid' system-call // as well as our external procedure for converting a value // into its representation as a string of decimal numerals. // // to assemble: $ as showpid.s -o showpid.o // and to link: $ ld showpid.o base10io.o -o showpid // // programmer: ALLAN CRUSE // written on: 07 FEB 2007 //--------------------------------------------------------------- # manifest constants .equ STDOUT, 1 # device-file ID-number .equ sys_EXIT, 1 # system-call ID-number .equ sys_WRITE, 4 # system-call ID-number .equ sys_GETPID, 20 # system-call ID-number .section .data pid: .int 0 # will hold process-ID msg: .ascii "\r\n process-ID is " # explanation of info buf: .ascii " \n\n" # shown in this string len: .int . - msg # length of the string .section .text _start: # get the pid for this process mov $sys_GETPID, %eax # system-call ID-number int $0x80 # request kernel service mov %eax, pid # store the return-value # convert the pid to a decimal string lea buf, %edi # buffer-address in EDI mov pid, %eax # number's value in EAX call eax2asc # convert EAX to string # display the report-message mov $sys_WRITE, %eax # system-call ID-number mov $STDOUT, %ebx # device-file ID-number lea msg, %ecx # address of the string mov len, %edx # length of that string int $0x80 # request kernel service # terminate this program mov $sys_EXIT, %eax # system-call ID-number mov $0, %ebx # use zero as exit-value int $0x80 # request kernel service .global _start # make entry-point visible .end # nothing else to assemble