A more structured approach



Hello,

After I've seen Frank's code to print out an specified envrinonment
variable, I'm trying to imitate it. Acutally I'm trying to know whether
the program has been called with it's name, or with a hard link I've
setup.

I've started by storing beginning and end addresses for the environment
variables, and then I wanted to look for PWD, and substract it's value
from the program's name. This is what I've got so far:

..section .data

pwd: .ascii "PWD"

..section .bss
.lcomm end_vars, 4
.lcomm start_vars, 4
..section .text
..globl _start

_start:
movl %esp, %ebp # save the stack pointer
movl $1, %edi # set edi to 1
movl 8(%esp, %edi, 4), %eax # mov before any command line
args
movl %eax, start_vars # save the address to
start_vars

find_end_vars:
cmpl $0, %eax # whatch out for the 0x0
delimiter
jz save_end_vars # go and save it if so
inc %edi # or increment edi by 1
movl 8(%esp, %edi, 4), %eax # move it onto the next address
jmp find_end_vars # and repeat it

save_end_vars:
decl %edi # substract 1 to edi
movl 8(%esp, %edi, 4), %eax # save the address on eax
movl %eax, end_vars # save it to end_vars

exit:
movl $1, %eax
movl $0, %ebx
int $0x80

Right after save_end_vars, I might need to start looking for PWD
string, I think I should use scas for this.
Basically I'd like anyone to tell me somethig about the approach used,
so I can have feedback o how I'm understanding assembler.

Kind Regards,

.