Jump to content

  • Log In with Google      Sign In   
  • Create Account

Inline assembler question...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Mike   Members   -  Reputation: 140

Like
Likes
Like

Posted 30 August 1999 - 09:33 PM

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.


Sponsor:

#2 bosjoh   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 August 1999 - 08:21 AM

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

#3 FlyFire   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 August 1999 - 08:36 AM

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,[+ 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


#4 FlyFire   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 August 1999 - 09:33 PM

I'v made a mistake in new code.
line lea eax,[ebx*4] must be replaced with
mov edx,[<BR>lea eax,&#91]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS