I'm a programmer with a background in high-level languages like Java, C#, and ActionScript. 

Recently however I've tried to branch out into the exciting worlds of Assembly and C/C++.  I really like Visual Studio as a native C compiler, so I decided to do inline assembly. 

My goal is to be able to have most of my code written in C, but have a handful of codes which are ran very often written in Assembly. 

But here's the thing I don't get...  Once I mov a variable in assembly to a location in memory like:

mov memLoc, eax ;where eax is a register

How do I access that variable in C?  I realize this is a very n00bish and stupid question, yet I am only beginning to learn Assembly. 

Also, how do I know where to put my finished data into memory.  I'm used to having the compiler automatically work with an unused location in memory like int a = 2;
Posted on 2007-04-01 10:35:19 by Al6200
I didn't get it correctly but I can give a sample

VOID
memset(
PVOID pMem,
BYTE bByte,
UINT uiLen )
{
__asm
{
mov edi, pMem
xor eax, eax
mov al, bByte
mov ecx, uiLen
rep stosb
}
}

C variables can be accessed like that example
Posted on 2007-04-01 10:56:17 by Dite

I didn't get it correctly but I can give a sample

VOID
memset(
PVOID pMem,
BYTE bByte,
UINT uiLen )
{
__asm
{
mov edi, pMem
xor eax, eax
mov al, bByte
mov ecx, uiLen
rep stosb
}
}

C variables can be accessed like that example


Thanks for the reply.  Would you mind if I asked some n00bly questions though? 

What's the point of xor eax, eax?  Won't it always just make eax 0, since eax and eax are always the same...  So basically you're just moving all these memory-defined vars into registers and then rep stosb?  What does rep stosb do? 

Are all of those registers you assigned to identical, or are they all different in terms of purpose? 

I'm sorry for asking so many n00b-like questions, but how do I actually use this code to good effect.  How do I know what memory is writable, so I can use it? 

And finally, how do I actually access the variables from the memset function.  I mean, I could make a pointer to pMem and then access the bytes like that, but is there any way just to create like an int that has the value of memset's result? 
Posted on 2007-04-01 11:34:55 by Al6200

What's the point of xor eax, eax?  Won't it always just make eax 0, since eax and eax are always the same... 

Yes, exactly it does. I'm usually use "xor eax,eax" instead of "mov eax, 0"


So basically you're just moving all these memory-defined vars into registers and then rep stosb?  What does rep stosb do? 
Are all of those registers you assigned to identical, or are they all different in terms of purpose? 

Here is a detailed explanation
http://www.online.ee/~andre/i80386/Opcodes/STOS-STOSB-STOSW-STOSD.html
Simply, It stores es:edi, al and increases edi by 1
mov byte ptr,al
inc edi

or
a very silly C convertion
char *pEdi;
*pEdi = al;
pEdi++;

Also there is detailed description for "rep xxxx" too
http://www.online.ee/~andre/i80386/Opcodes/REP-REPE-REPZ-REPNE-REPNZ.html#REP/REPE/REPZ/REPNE/REPNZ
But simply it's means that
Do action "xxxx" and decrease ecx till zero


I'm sorry for asking so many n00b-like questions, but how do I actually use this code to good effect.  How do I know what memory is writable, so I can use it? 

This code is just simple, not optimized. You can test memory for writing with "IsBadWritePtr" api
Posted on 2007-04-01 15:29:03 by Dite
Imho you're better off using an external assembler for those few routines, instead of inline assembly. You get the full capabilities of an assembler, you can use the external assembly with multiple C compilers (inline assembly differs a bit between the various compilers), etc.
Posted on 2007-04-03 10:00:42 by f0dder