• Advertisement

Archived

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

Inline assembler question...

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

I recommend that you multiply in C++ or you can shift left the index by 2 (shl EBX,2).

Share this post


Link to post
Share on other sites
Advertisement
You don't need to use shl,2 because *4 works good (and faster) too.

some errors here:
1)
mov eax,array[ebx*4] <- you get array alement here, but you need it's address.
2)
mov [eax],value <- intel processors does not support mem-to-mem moving


Try to enclose parameters in square brackets, like this:
mov ebx,[index]
mov edx,[value]
lea eax,[array + ebx*4] <- get address of an element
mov [eax],edx

Also, leave these uptimizations for compiler, i think it can jenerate code better.

------------------
FlyFire/CodeX
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites
What's wrong here:

void SetValue( int* array, int index, int value )
{
_asm
{
MOV EBX, index
MOV EAX, array [EBX*4]
MOV [EAX], value
}
}

I realize that this is a usless function really, but I'm just starting to learn assembly. I'm using VC++ 6 (hence EBX and EAX instead of BX and AX). I multiply by 4 because intigers in VC++ are 4 bytes.

Share this post


Link to post
Share on other sites

  • Advertisement