Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mulligan

accessing member vars in assembly

This topic is 5878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a member function, why isn't it possible to access meber variables directly? for instance: void someclass::foor() { __asm mov ebx,m_iVariable } do I have to do this:? void someclass::foor() { int iVar = iVariable; __asm mov ebx,iVar } If you can't tell, I'm new to assembly Oh yea, one other thing while I'm asking newbie questions. I have this code: double distx = 5.0; double radius; __asm { mov ax, distx mov cx, ax // error C2443: operand size conflict mul cx mov ax, bx mov radius, bx } Which gives me the error on the line above. Why is this? [edited by - Mulligan on September 9, 2002 7:15:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
When you access member variables in c++ code, you''re implicitly accessing them through the this pointer. My guess is that you need to do that explicitly in the assembly code. I think the syntax is:

__asm mov ebx, someclass PTR [this].m_iVariable

Share this post


Link to post
Share on other sites
To answer you second question:

I think the error you are getting is not on the line you indicated, but on the line above. You are trying to assign a double value to a 16-bit integer register. Obviously this will not work.

try something like this (may not compile! use as an example and go look it up )



double distx = 5.0;
double radius;
__asm
{
fld [distx]
fmul [distx]
fstp [radius]
}



There are different types of registers in the cpu. Some store whole integer value, some store floating point (fractional) values. Your code was trying to assign a fractional value to an integer register. For more information, go to the developers section on the intel web site and download a few manuals.


[edited by - Jx on September 10, 2002 8:48:15 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Mulligan
Oh yea, one other thing while I''m asking newbie questions. I have this code:

double distx = 5.0;
double radius;
__asm
{
mov ax, distx
mov cx, ax // error C2443: operand size conflict
mul cx
mov ax, bx

mov radius, bx
}

Which gives me the error on the line above. Why is this?



As far as I can remember, cx is an 16 bit register. Try replacing cx with ecx( as ecx is supposed to be the 32 bit equivalent of cx ). I''m a bit rusty in assembler...
That should work for you though...










find your element
at mutedfaith.com.
<º>


Cyberdrek

Share this post


Link to post
Share on other sites
I always wanted to know how you determined which register to use in assembly. That part always confused me.

Share this post


Link to post
Share on other sites
quote:
Original post by daerid
I always wanted to know how you determined which register to use in assembly. That part always confused me.


use eax, ebx, ecx, edx when storing 32 bit values

use ax, bx, cx, dx when storing 16 bit values

use ah, al etc when storing 8 bit values

use MM0 - MM7 for MMX registers

use XMM0 - XMM7 for SSE registers

use ST0 - ST7 for FPU registers

use ebp and esp to access the stack

use eip rarely it is the instruction pointer

use ds, es, fs, gs when you need segments in 16bit code or as a segment selector in 32bits. you shouldn''t need to play with these at all really

There are a few other registers which are special so I won''t go into them here...

When deciding, just pick which data type you need really. Of course, if you perform an instruction using EAX it affects AX, AH and AL because AX is actually just the lower 16 bits of EAX. AH is the higher 8 bits of AX, and AL is the lower 8 bits of AX.

Phew.. hope that gets the point across

Share this post


Link to post
Share on other sites
Thanks, explained much. Now I can do floating point arithmitic on 'float's but not 'double's. Any bigger better registers for that?
Anyway, this compiles bacause i changed everything to 'float':
__asm
{
mov eax, distx
mov ebx, eax
mul ecx
mov ebx, eax

mov eax, disty
mov ecx, eax
mul ecx
add ebx, eax

mov eax, distz
mov ecx, eax
mul ecx
add ebx, eax

mov dRadius, ebx
}

this block represents the C++ form of this:
dRadius = distx*distx + distz*distz + disty*disty;

...but it doesn't work. I'm still an seembly idiot, so let into me if im doing really stupid mistakes.

One last question, which may answer the question above, when I execute the command "mul eax" which registers are multiplied? The result is left in eax, correct?

[edited by - Mulligan on September 11, 2002 11:22:53 PM]

Share this post


Link to post
Share on other sites
I belive i see your problem (assuming that was a copy and paste)
in the first block you are moving eax into ebx but then mul eax by ecx, which is either gonna be zero or a random value depending

also, as a side note, isnt it good practise with asm routines to push onto the stack any registers you plan on using and then poping them off at the end, as the process or is probably using ''em to hold data


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!