Ron
Ron

Reputation: 2503

Modify array using Assembly Language

I am trying to figure out how to modify the values in an array using assembly language. Here's the program:

#include "stdafx.h"

#include <windows.h>  

void  func(byte *p)
{ 
    __asm
    {
        lea ebx, p 
        mov[ebx],5 
    }

}
int _tmain(int argc, _TCHAR* argv[])
{
    using byte = unsigned char;

    byte array[4];
    for (int i = 0; i < 4; i++)
        array[i] = i*i;

    func(array);
    return 0;
}

When I step into func I can see that p points to the array. *(p+1) is 1, *(p+2) is 4, etc. I would like func to set *p to 5 but while it doesn't error out, it doesn't do that.

What I wanted to do is put the address of p into ebx and move 5 into that, but obviously I am not.

Upvotes: 1

Views: 691

Answers (1)

JSF
JSF

Reputation: 5321

lea ebx, p means ebx=&p, but you wanted ebx=p, which would be mov ebx,p

Upvotes: 4

Related Questions