News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What should I put on stack?

Started by Farabi, October 29, 2010, 02:17:57 PM

Previous topic - Next topic

Farabi

If I had a struct like this on C

struct glObject{
GLuint nPlanes, nPoints;
sPoint points[100];
sPlane planes[200];
};


What should I put to stack if the function parameters is like this

1. SetConnectivity(glObject *o)
2. CalcPlane(glObject o, sPlane *plane)
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Sorry, wrong room, can anyone move it?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Twister

It would just be the address of where the data structure is located in the memory.

invoke SetConnectivity, offset glObject

Farabi

what about CalcPlane? The whole glObject? (More than 3 kb)
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Antariy

Quote from: Farabi on November 01, 2010, 01:49:30 AM
what about CalcPlane? The whole glObject? (More than 3 kb)

It is have that prototype:

CalcPlane(glObject o, sPlane *plane)

?

If that - this is something strange, where you found that function? That is not usual - put entire objects into the stack - firstly that is slow, second - changes in it would be lossed after exiting from function.




Alex

Twister

I am thinking that you would just pass the address of the data structure for CalcPlane.

redskull

Quote from: Farabi on November 01, 2010, 01:49:30 AM
what about CalcPlane? The whole glObject? (More than 3 kb)

Assuming this is straight C, then yes, all 3kb on the stack.  But like Alex said, that is certainly strange, and probably points to a mistake in the design (e.g. something from Java hastily ported to C++, or something like that).  Better to use a const pointer.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Antariy

Quote from: redskull on November 01, 2010, 02:07:04 AM
(e.g. something from Java hastily ported to C++, or something like that).  Better to use a const pointer.

Yes, that is looks like simple translation - maybe that is been C++ reference to constant object, or this is really port from Java (which is made this under the hood).

But if Onan have that as library (dll or lib) - one way to change this - hardly patch things... oh, sorry  :green2 - find the author  :bg



Alex

Antariy

Instead of modifying, I posted  :green2

Farabi

Life to short, I dont have time to understand all of how is that function works so I guess I will create this as a dll and use it
Got it from here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=27
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

ramguru

I think it's pretty obvious what's going on with CalcPlane(glObject o,..
In high-school you learn that pointers are dangerous and it's better to avoid them,
you ONLY use pointer when you wanna change variable's value, that's a common practice.
If you never looked into lower layers of programming code you aren't the least interested of how stack works
and how it will affect performance.
So the conclusion is: as a asm programmer you can't follow everything blindly, put your brain to work,
make clear picture of the code & translate it to your need.

redskull

Ah, who cares about the stack; I'm sure the optimizer will handle it  :bg
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Farabi

Any lawyer here, please tell me if Im doing something wrong? I had no money to consult to lawyer here.
I need to know what is my right and what is my obligation.

All of my code is permission granted.


Thank you.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Antariy

Quote from: Farabi on November 01, 2010, 03:21:59 PM
Any lawyer here, please tell me if Im doing something wrong? I had no money to consult to lawyer here.
I need to know what is my right and what is my obligation.
All of my code is permission granted.
Thank you.

I'm really have no looked into the sources which you are pointed, yet.
But, at first look, if you'll change declaration and function start that:

CalcPlane(const glObject& o, sPlane *plane)


it is would be not needed to pass entire object.
From ASM you will call it like that:

invoke CalcPlane,offset o_glObject, offset plane_sPlane


You must use C++ compiler for that.



Alex

Antariy

To make clear:

Current code in "3DObject.h" file is:

........

inline void CalcPlane(glObject o, sPlane *plane){
sPoint v[4];
int i;

for (i=0;i<3;i++){

.........



So, you should just replace the function declaration/start that:

inline void CalcPlane(const glObject& o, sPlane *plane){


To see changes, that is repeating with color:

inline void CalcPlane(const glObject& o, sPlane *plane){

After that, you just needed to compile the sources with C++ compier, not C.
And use resulting .OBJ with ASM program as I sayed in previous post.

This solution will use pointer to the object, without any other changements in the HLL code.



Alex