//---------------------------------------------------------------- // showvars.s // // This program displays this task's environment variables. // // assemble using: $ as showvars.s -o showvars.o // and link using: $ ld showvars.o -o showvars // // programmer: ALLAN CRUSE // written on: 21 FEB 2006 //---------------------------------------------------------------- .equ sys_exit, 1 .equ sys_write, 4 .equ STDOUT, 1 .section .data eoln: .ascii "\n" # newline control-code .section .text _start: # setup base-address of the envp[] array in EBP movl 0(%esp), %eax # count of the cmd-args leal 8(%esp, %eax, 4), %ebp # base of envp[] array cld # use forward scanning nxvar: cmpl $0, (%ebp) # null array-element? je quit # yes, no more to show movl (%ebp), %edi # point EDI to string movl $0x1000, %ecx # setup default count movb $0, %al # target byte is null repne scasb # scan for null byte decl %edi # omit that null byte subl (%ebp), %edi # total chars in string andl $0x3F, %edi # truncate to fit screen movl $sys_write, %eax # service-ID for 'write' movl $STDOUT, %ebx # device-ID for terminal movl (%ebp), %ecx # point to env-string movl %edi, %edx # setup length to write int $0x80 # request kernel service movl $sys_write, %eax # service-ID for 'write' movl $STDOUT, %ebx # device-ID for terminal leal eoln, %ecx # point to newline string movl $1, %edx # specify string's length int $0x80 # request kernel service addl $4, %ebp # advance array's address jmp nxvar # and show another string quit: movl $sys_exit, %eax # service-ID for 'exit' movl $0, %ebx # specify the exit-code int $0x80 # request kernel service .global _start # make entry-point visible .end # no more lines to assemble