Here is my code:
void Graph::PutPixel(DWORD x, DWORD y, DWORD c)
{
__asm
{
Mov Eax, y
Mov Ebx, _width
Mul Ebx
Add Eax, x
Shl Eax, 2 // Multiply by four
Add Eax, _buffer
Mov Edi, Eax
Mov Eax, c
StosD
}
}
Where _buffer and _width are Graph class members:
private:
DWORD _width;
DWORD* _buffer;
It does not work; I get 0 value from both variables, but they have some other values in fact.
I can fix it by copying class variables to local variables and using them:
void Graph::PutPixel(DWORD x, DWORD y, DWORD c)
{
DWORD bufAddr = (DWORD)_buffer;
DWORD w = _width;
__asm
{
Mov Eax, y
Mov Ebx, w
Mul Ebx
Add Eax, x
Shl Eax, 2 // Multiply by four
Add Eax, bufAddr
Mov Edi, Eax
Mov Eax, c
StosD
}
}
What’s the problem with direct usage? Is it possible?
On the off chance that you have something that really does need assembly (see Bo’s answer), there is an article here on accessing C or C++ data in inline assembly blocks.
In your case we get: