Eutherpy
Eutherpy

Reputation: 4581

Print environment variables in NASM

I am trying to figure out how to print environment variables in NASM.

We learned in class that the number of command line arguments is stored in the EAX register, and the address of the first argument is stored in the location which is in the EDX register. However, this doesn't work for me since there is nothing written in the EDX register.

I have seen some other ways to do this, where the ESP register was used in some way, but I didn't really find a complete explanation.

I'd be very grateful if someone had a nice and clear explanation of this - for me - confusing matter.

Upvotes: 2

Views: 3666

Answers (1)

Igor Ševo
Igor Ševo

Reputation: 5525

Take a look at the following related post: Why does this NASM code print my environment variables?.

You can also take a look at the startup state of a Linux binary.

In short, environment variables are listed after a NULL value which follows command line arguments.

Upvotes: 2

Related Questions