I'm trying to get a hold of assembly, but there's one probably very simple thing I don't understand.
Consider this following simple example
long long * values = new long long[2]; values[0] = 10; values[1] = 20; int j = -1; values[j+2] = 15; // xxxxxxx Now, the last line (marked with xxxxxx) disassembles to:
000A6604 mov eax,dword ptr [j] 000A6607 mov ecx,dword ptr [values] 000A660A mov dword ptr [ecx+eax*8+10h],0Fh First question: What is actually stored in eax and ecx, is it the actual values (i.e. -1 for "j", and the two long long values 10 and 20 for "values"), or is it merely a memory address (e.g. someting like &p, &values) pointing to some place where the values are being stored?
Second question, I know what the third line is supposed to do, but I'm not quite sure why this actually works. So my understand is, it copies the value 0x0F into the specified memory location. The memory location is basically - the location of the first element stored in ecx - plus the size of long long in bytes (= 8) * the value of eax (which equals j, so -1) - plus the generic offset of 16 bytes (2 times the size of long long). What I don't get is: In this expression, ecx seems to be a memory address, while eax seems to be a value (-1). How is this possible? Seeing they were defined in pretty much the same way, shouldn't eax and ecx either both contain memory addresses, or both values?
Thanks.
jandvaluesrespectively. The value ofvaluesis in turn the address of a chunk of memory. Writing something likemov ecx, OFFSET valueswould be like taking the address of a pointer in C, which gives you a pointer to a pointer.jandvalueshave different types in your C code too.