Thread: Pointer question

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    93

    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;

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    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.
    Fact - Beethoven wrote his first symphony in C

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    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"

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to pointer question
    By Konstantinos in forum C Programming
    Replies: 2
    Last Post: 12-08-2013, 05:15 PM
  2. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 11:59 AM
  3. pointer question.... pointer theory?
    By panfilero in forum C Programming
    Replies: 6
    Last Post: 11-12-2005, 02:29 AM
  4. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  5. pointer to pointer as argument question
    By Lateralus in forum C Programming
    Replies: 4
    Last Post: 07-21-2005, 05:03 PM