开发者

moving data between Assembler Registers

What is the purpose of just several 'mov' type statements one after another in Assembler. It seems to me that just moving data between different registers is rather 'purposeless', although it most likely not so.

Example:

 Worker work = new Worker();  // C# statement
00000035 B9 40 9E 31 00   mov         e开发者_Go百科cx,319E40h 
0000003a E8 95 0A 9A FF   call        FF9A0AD4 
0000003f 89 45 BC         mov         dword ptr [ebp-44h],eax 
00000042 8B 4D BC         mov         ecx,dword ptr [ebp-44h] 
00000045 E8 0E B0 9B FF   call        FF9BB058 
0000004a 8B 45 BC         mov         eax,dword ptr [ebp-44h] 
0000004d 89 45 C0         mov         dword ptr [ebp-40h],eax

The following C# statement results in the assembler below it, what is the purpose of moving things between the ecx and eax registers? That's where I'm at a loss...


mov   ecx,319E40h   // probably a value uniquely identifiying the classtype?
call  FF9A0AD4      // call a routine on it? puts result in eax probably
mov   dword ptr [ebp-44h],eax  // save result(eax) to a localvariable
mov   ecx,dword ptr [ebp-44h]  // reload the local parameter to ecx, probably 
                               // the reference to the new class instance.
call  FF9BB058                 // some function on the instantiated class.
mov   eax,dword ptr [ebp-44h]  // reload the reference
mov   dword ptr [ebp-40h],eax  // store to another local variable.

So my guess is that the first routine called is the instantiation, and the ebp-40 is the worker variable. And that the second routine is something related to memory management, the constructor or something that needs to be done when assigning a reference. Mostly probably constructor.

But as said this is just an educated guess.


Most assembly instructions need input (think function arguments), and just as most languages require you to pass arguments in a particular order, the assembly instruction assumes its arguments will be in a particular order - specifically, will exist in particular registers.

Also, the final two lines are likely there because mov from memory location to memory location using indirection may not be supported - the data must be moved from memory to register, then register to new memory location.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜