🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Inline assembler question...

Started by
2 comments, last by Mike 24 years, 9 months ago
I recommend that you multiply in C++ or you can shift left the index by 2 (shl EBX,2).
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

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.

I'v made a mistake in new code.
line lea eax,[array+ebx*4] must be replaced with
mov edx,[array]
lea eax,[edx+ebx*4]

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

This topic is closed to new replies.

Advertisement