The MASM Forum Archive 2004 to 2012

Project Support Forums => HLA Forum => Topic started by: jaysicks on December 06, 2011, 04:15:47 PM

Title: question about the activation record
Post by: jaysicks on December 06, 2011, 04:15:47 PM
Hi,
my question is: how exactly the parameters stored in the activation record?

I've read about the topic a lot, but
the problem is, when the parameters are any of "smaller-than-4-bytes" datatypes.

For example:
Procedure proc(VAL i:int32; VAL j:int16; VAL k:int16);@nodisplay;

since it isn't mentioned anywhere, that all parameters allocate (at least) a 4-bytes blocks,
I would expect k to be on EBP+8, j on EBP+10 and i on EBP+12.

But according to a few stdout.puts, it's not the case.
k is on EBP+8, j is on EBP+12, and i is on EBP+16.

Is it really the case? Has it always been this way?

sidenote: I wouldn't be surprised, if I had used VAR instead of VAL, but I didn't :/

Thanks in advance
Title: Re: question about the activation record
Post by: Sevag.K on December 23, 2011, 03:32:13 AM
var and val both need the same amount of storage, the only difference being in how they are treated for the purpose of data access.

all the parameters are stored in the stack, and they are done in a specific way given that you are using high level procedure declarations, i can't remember exactly where, but i believe it is mentioned that 4-bytes are used.  the way hla does it is typical to the way it's done by high level languages, but in hla, you have full control and you can build your own activation record if you add the @noframe switch.

Title: Re: question about the activation record
Post by: MichaelW on December 23, 2011, 05:50:53 AM
Per Agner Fog's calling_conventions.pdf, available  here (http://www.agner.org/optimize/):
Quote
The stack pointer must be aligned by the stack word size at all times.
In 32-bit code the stack word size is 32 bits. I don't know about HLA, but for MASM when the invoke directive is presented with a word (2-byte) argument, it maintains the stack pointer alignment by pushing a word with the value of zero before it pushes the argument.