-
Pointer question
Crazy question but, are these two examples equivalent?
Example 1:
MOV EAX, lpvar ; Copy address into EAX
MOV EAX, [EAX] ; Dereference it....Moves the contents of memory pointed to by eax into the eax register.
MOV nuvar, EAX ; Copy EAX into new variable
Example 2:
LPINT lpvar;
INT nuvar;
nuvar = *lpvar;
-
Yes? No? I don't know.
LPINT and INT are not C types, though they may be some implementation-specific types. A quick Google search suggests it might be a MS thing and that LPINT is a pointer to int. I guess INT would be just an int, but who the heck knows. Also, you don't tell us much about the architecture your assembly code is in. Sure, it looks like x86, but it could be something else; I can't recognize all possible architectures by a simple 3-line assembly snippet. And sure, the comments suggest Intel syntax, but it wouldn't be a first if comments and code didn't match up. It would be nice if you gave us all the details we would need.
My smart-ass-ness asside, I'm guessing they are -- they look equivalent, especially if the comments are to be believed.
You could also try putting the C code in .c file and compiling it to assembly (check your compiler documentation) to see if it genrates the same instructions.
-
You might get better answers in the "Tech Board" thread, as this section is for C programming and your question is specifically on Assembly language.
-
If you're using gcc, you could always use the -S option and have a look. gcc -S myprog.c
Edit: but of course if gcc outputs different code it doesn't mean that your code is not "equivalent"
-
Sorry about the vague post. I was looking up some info on pointer to pointer and came across this snipit of ASM code referring to dereferencing pointers. I've seen these three lines of ASM a few times in the past and was wondering what the C language equivalent would be. The ASM was supposed to be Intel x86...Sorry about the capitals. Likewise, I apologize for my C example...I had Windows programming on my mind when I wrote this.
-
Well, I did compile the C code and the resulting ASM did match what I posted earlier....So, now I know what 'mov eax, [eax]' (dereferencing of a pointer) represents in C.