0

I am trying to compare the assembly for two pieces of code and they look like shown below. My question is if the additions in [esp+4] [esp+8] [esp+0Ch] are performed at run-time, or somehow resolved before that.

Version 1

00FE104D  mov         eax,dword ptr [esp+4]  
00FE1051  imul        eax,dword ptr [esp+8]  
00FE1056  mov         esi,dword ptr [esp+0Ch]  

Version 2

00FE104D  mov         eax,dword ptr [x]  
00FE1051  imul        eax,dword ptr [y]  
00FE1056  mov         esi,dword ptr [z]  
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Aedoro
  • 609
  • 1
  • 6
  • 21

1 Answers1

0

It's of course performed at runtime. "resolving" it before would be pointless.

mov eax,dword ptr [x]

means: take whatever DWORD pointed by x and put it into eax. In C it would be something like this:

   DWORD x;
   ...
   eax = *((DWORD*)x);

   mov eax,dword ptr [x + 4]

would be something like this in C

   DWORD x;
   ...
   eax = *((DWORD*)(x + 4));
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • Ok thank you for clarifying, as a second question, is there a difference in performance between version 1 and version 2? (with or without those additions). – Aedoro Feb 21 '19 at 11:50
  • 1
    `*((DWORD*)x)` <-- Wouldn't it be `*((DWORD*)&x)`? The address is the address of `x`, not the value stored at `x` treated as an address. – Michael Feb 21 '19 at 12:16
  • @Michael this is more pseudo code just to explain what the assembly instruction does. So, yes, in this sample `x` contains a 32 bit address. – Jabberwocky Feb 21 '19 at 12:23
  • 2
    Well, if it's not clear exactly how we should interpret the explanation, then the answer gets a bit confusing. If it's C then it seems like there should be an ampersand before `x`, because that's what the assembly code really means. If it's not C then there should probably be some kind of explanation of what those expressions mean in this language. – Michael Feb 21 '19 at 12:29