delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/06/02:24:54

Date: Thu, 5 Feb 1998 20:55:08 -0800 (PST)
Message-Id: <199802060455.UAA04123@adit.ap.net>
Mime-Version: 1.0
To: "Rylan" <rylan AT intekom DOT co DOT za>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: NASM: Passing 2nd Parameter

At 01:00  2/5/1998 GMT, Rylan wrote:
[snipped]
>I read that C stores parameters to a function on the stack in reverse
>order. Should I then use an index value of 8 + ??? for the first parameter
>to the function, and just 8 for the second parameter? What is the number to
>use where ??? is to access second, third and n parameters?
It pushes the rightmost (last) arg first, and the leftmost (first) arg last.
This means the first arg ends up being the closest to the top of the stack.

A diagram may help here. This is the stack.

        [Last arg]
        ....
        [First arg]
        [Return address]
        [Saved EBP]   ______ EBP points here.

So, assuming all your args are longword size (int or pointer), arg X will be
at address:
[ebp + 8 + 4*(X-1)]
It gets more difficult if you want to pass `long long's or structs. Advice:
Try not to. :) You have to compute where they are by when they were pushed
and how large they are.
>
>The grand question then: how to pass multiple parameters between Nasm and
>C, using the stack?
I hope this has answered your question. If not, let me know.
>
>Please reply by mail if possible.
>
>Any replies appreciated! :)
>-- 
>Spawned By Rylan
>Is truth beauty or beauty truth?
>
>

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019