Skip to main content
gamedev.net
🔒 Locked

Objects and inline ASM problem

Started by persil 1 reply 250+ views
Original Post
persil
persil
Ok, here''s my problem. I didn''t want to have tons of parameters passed to many functions, so I decided to create a container class, which has all its members within. Thus calling the functions would require no parameters and they would just have to use the class members as parameters. I hope I''m clear enough. Now, the problem is, these functions are inline ASM, so when I actually want to get the class member''s content, I found out that I have to load the this pointer and add the offset which is contained in the members, instead of their content. Is there an efficient way to use class members in an ASM routine? Here''s a quick example of what I mean: class test { private: int a; char * ptr; void asmproc () { __asm { mov eax, a // this will move the offset of a instead of its value mov ebx, this mov eax a[ebx] // this will work correctly, but I have to sacrifice a register all the time for this to work } }; public: void dosomething (int a, char * ptr) { this->a = a; this->ptr = ptr; asmproc(); }; }
iMalc
iMalc
Exactly how many parameters is "tons of parameters"? More than six?
Also, are there a lot that are of the same type?
You may be able to reduce the number of parameters by using default values.

If you''re using inline asm then obviously performance is your primary concern. If so lots of parameters might just be the best option. And if it isn''t then why are you using asm?
persil
persil
Ok, lots means about up to 10 sometimes... And I''ve checked out the code generated by the compiler and it uses many "push", just to load each parameter, I thought that using class members could avoid this series of push, but instead, I have to load the "this" pointer, which is also awkward when optimizing.

About default values, it''s not something that would help I think.

Yes, it''s for optimizing. I''m "patching" over DirectDraw many blit functions which enable alpha blending and per-pixel alpha.

The way I work, the actual "game" calls a uniform Blit function, which dispatches the right optimized blit function. It also initializes (clip, lock, calculate padding, etc..) the blit before calling the optimized blit function, to avoid too much redundancy. That''s why I had to pass many parameters to the function.

Blit (CSurface * DestSurface, CSurface * SrcSurface, dwDestWidth, dwDestHeight, dwDestWidthClipped, dwDestHeightClipped, dwSrcWidth, dwSrcHeight, dwDestPad, dwSrcPad, dwStartX, dwStartY, dwStopX, dwStopY);

That''s an example of what it looked like, I found it very awckward working with this.

That''s why I thought of using objects. I thought that the base stack pointer always pointed to the object''s members or that there was a way to do this, but it seems not???

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.