Mysterious item on stack

Everything else that doesn't fall into one of the other PB categories.
veganisafreak
User
User
Posts: 32
Joined: Mon Jun 02, 2008 6:55 pm
Location: UK

Mysterious item on stack

Post by veganisafreak »

Hello, I have found Mysterious Item on Stack.

I could end my post there but that's not very informative.

Right, I was looking at the stack trace window, trying to find out where PB stores a procedure's local variables... the manual doesn't have much to say about it... and I found that in between the procedure's arguments, and the local variables, there was another 32 bit value that I didn't know what it was...

Does anyone know?

Can I rely on it being there all the time? Did I dream this?

PS I thought it might be a saved EBP but since PB uses ESP to reference stack variables, it wouldn't need to save EBP would it?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

... the manual doesn't have much to say about it...
Why should it, it's really an internal matter? Anyhow, the first thing PB does in a procedure is push the EBX register, to be popped at procedure's end.
I may look like a mule, but I'm not a complete ass.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Mysterious item on stack

Post by tinman »

veganisafreak wrote:Right, I was looking at the stack trace window, trying to find out where PB stores a procedure's local variables... the manual doesn't have much to say about it... and I found that in between the procedure's arguments, and the local variables, there was another 32 bit value that I didn't know what it was...
Return address?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Just compile your code with the /commented switch from a console and you can look
at the assembly code to see what is done exacly when calling the procedure.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

srod wrote:
... the manual doesn't have much to say about it...
Why should it, it's really an internal matter? Anyhow, the first thing PB does in a procedure is push the EBX register, to be popped at procedure's end.
That's only if it's used.

The number in between is the return address.
veganisafreak
User
User
Posts: 32
Joined: Mon Jun 02, 2008 6:55 pm
Location: UK

Post by veganisafreak »

Thanks everyone. :)

Especially freak I was wondering how to get hold of the asm output!
veganisafreak
User
User
Posts: 32
Joined: Mon Jun 02, 2008 6:55 pm
Location: UK

Post by veganisafreak »

This sunk in over the last couple days. I can't believe I referred to the return address as a mysterious item. What an idiot. I assumed the return address would be higher up the stack somewhere...
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I guess PB pushes the ReturnAdr first and then the Parameters,
because the Params need to be popped in the beginning of the procedure,
but the ReturnAdr only at the end....
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

PB never pushes the return address "conciously", the processor pushes it automatically when it runs the call instruction.
Post Reply