Note that there are some explanatory texts on larger screens.

plurals
  1. POanalyzing assembly code of some c++ code
    primarykey
    data
    text
    <p>I were asked to analyze an assembly code, which was generated from following c++ code in Visual studio IDE:</p> <p>here is c++ code:</p> <pre><code> int plus(int a,int b); int main() { cout&lt;&lt;plus(2,4); getchar(); return 0; } int plus(int a,int b) { static int t=2; return a+b+t; } </code></pre> <p>And here is the assembly code (the reduced form):</p> <pre><code>_main PROC ; COMDAT ; 8 : { push ebp mov ebp, esp sub esp, 192 ; 000000c0H push ebx push esi push edi lea edi, DWORD PTR [ebp-192] mov ecx, 48 ; 00000030H mov eax, -858993460 ; ccccccccH rep stosd ; 9 : cout&lt;&lt;plus(2,4); push 4 push 2 call ?plus@@YAHHH@Z ; plus add esp, 8 mov esi, esp push eax mov ecx, DWORD PTR __imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A call DWORD PTR __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z cmp esi, esp call __RTC_CheckEsp ; 10 : getchar(); mov esi, esp call DWORD PTR __imp__getchar cmp esi, esp call __RTC_CheckEsp ; 11 : return 0; xor eax, eax ; 12 : } pop edi pop esi pop ebx add esp, 192 ; 000000c0H cmp ebp, esp call __RTC_CheckEsp mov esp, ebp pop ebp ret 0 _main ENDP ; Function compile flags: /Odtp /RTCsu /ZI _TEXT ENDS ; COMDAT ?plus@@YAHHH@Z _TEXT SEGMENT _a$ = 8 ; size = 4 _b$ = 12 ; size = 4 ?plus@@YAHHH@Z PROC ; plus, COMDAT ; 15 : { push ebp mov ebp, esp sub esp, 192 ; 000000c0H push ebx push esi push edi lea edi, DWORD PTR [ebp-192] mov ecx, 48 ; 00000030H mov eax, -858993460 ; ccccccccH rep stosd ; 16 : static int t=2; ; 17 : return a+b+t; mov eax, DWORD PTR _a$[ebp] add eax, DWORD PTR _b$[ebp] add eax, DWORD PTR ?t@?1??plus@@YAHHH@Z@4HA ; 18 : } pop edi pop esi pop ebx mov esp, ebp pop ebp ret 0 ?plus@@YAHHH@Z ENDP ; plus _TEXT ENDS END </code></pre> <p>I have to find how does the code deal with stack and how variables stored and retrieved? Regards.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload