Sign in to follow this  

Need help for using pointers with assembly?

This topic is 3814 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

Hi I'm writing some functions involving vector manipulations and want to know the addressing modes for using pointer types with MSVC inline assembler such as "mov eax, [some pointer type] ".

Share this post


Link to post
Share on other sites
You first need to load the value of the pointer into a register:

mov esi,pointer_var

Then you deference the pointer:

mov eax,dword ptr [esi].member

The inline assembler in MSVC can add the correct offset to the pointer value for the given member.

Skizz

Share this post


Link to post
Share on other sites
thx for the answer. Do I always need to move the pointer to the register ? ( Are there any specific registers for this or can I use anyone of them? ). What is the "dword ptr" prefix?

Share this post


Link to post
Share on other sites
Yes, on the IA32 architecture you always need to move the pointer value to a register before dereferencing it. You can use any register but be aware that not all registers use the same default segment. For example, ebp uses the ss segment by default so doing the following could end up with different physical addresses:

mov eax,pointer_value
mov ebp,pointer_value
mov ecx,dword ptr [eax]
mov edx,dword ptr [ebp] ; edx may not equal ecx

The 'dword ptr' bit helps the assembler generate the correct output. Consider the following:

movzx eax,[esi]

This is an ambiguous instruction as the source operand can be either a word or a byte, so the 'word ptr' or 'byte ptr' tells the assembler which version to use.

Skizz

Share this post


Link to post
Share on other sites

This topic is 3814 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this