Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferences in dis-assembled C code of GCC and Borland?
    text
    copied!<p>Recently I have gotten interested into dis-assembling C code (very simple C code) and followed a tutorial that used Borland C++ Compiler v 5.5 (compiles C code just fine) and everything worked. Then I decided to try my own c code and compiled them in Dev C++ (which uses gcc). Upon opening it in IDA Pro I got a surprise, the asm of gcc was really different compared to Borland's. I expected some difference but the C code was EXTREMELY simple, so is it just that gcc doesn't optimize as much or is it that they use different default compiler settings?</p> <p>The C Code</p> <pre><code>int main(int argc, char **argv) { int a; a = 1; } </code></pre> <p>Borland ASM</p> <pre><code>.text:00401150 ; int __cdecl main(int argc,const char **argv,const char *envp) .text:00401150 _main proc near ; DATA XREF: .data:004090D0 .text:00401150 .text:00401150 argc = dword ptr 8 .text:00401150 argv = dword ptr 0Ch .text:00401150 envp = dword ptr 10h .text:00401150 .text:00401150 push ebp .text:00401151 mov ebp, esp .text:00401153 pop ebp .text:00401154 retn .text:00401154 _main endp </code></pre> <p>GCC ASM (UPDATED BELLOW)</p> <pre><code>.text:00401220 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ .text:00401220 .text:00401220 ; Attributes: bp-based frame .text:00401220 .text:00401220 public start .text:00401220 start proc near .text:00401220 .text:00401220 var_14 = dword ptr -14h .text:00401220 var_8 = dword ptr -8 .text:00401220 .text:00401220 push ebp .text:00401221 mov ebp, esp .text:00401223 sub esp, 8 .text:00401226 mov [esp+8+var_8], 1 .text:0040122D call ds:__set_app_type .text:00401233 call sub_401100 .text:00401238 nop .text:00401239 lea esi, [esi+0] .text:00401240 push ebp .text:00401241 mov ebp, esp .text:00401243 sub esp, 8 .text:00401246 mov [esp+14h+var_14], 2 .text:0040124D call ds:__set_app_type .text:00401253 call sub_401100 .text:00401258 nop .text:00401259 lea esi, [esi+0] .text:00401259 start endp </code></pre> <p>GCC Update Upon following the suggestion of JimR I went to see what sub_401100 is and then I followed that code to another and this seems to be the code (Am I correct in that assumption and if sowhy does GCC have all of its code in the main function?):</p> <pre><code>.text:00401100 sub_401100 proc near ; CODE XREF: .text:004010F1j .text:00401100 ; start+13p ... .text:00401100 .text:00401100 var_28 = dword ptr -28h .text:00401100 var_24 = dword ptr -24h .text:00401100 var_20 = dword ptr -20h .text:00401100 var_1C = dword ptr -1Ch .text:00401100 var_18 = dword ptr -18h .text:00401100 var_C = dword ptr -0Ch .text:00401100 var_8 = dword ptr -8 .text:00401100 .text:00401100 push ebp .text:00401101 mov ebp, esp .text:00401103 push ebx .text:00401104 sub esp, 24h ; lpTopLevelExceptionFilter .text:00401107 lea ebx, [ebp+var_8] .text:0040110A mov [esp+28h+var_28], offset sub_401000 .text:00401111 call SetUnhandledExceptionFilter .text:00401116 sub esp, 4 ; uExitCode .text:00401119 call sub_4012E0 .text:0040111E mov [ebp+var_8], 0 .text:00401125 mov eax, offset dword_404000 .text:0040112A lea edx, [ebp+var_C] .text:0040112D mov [esp+28h+var_18], ebx .text:00401131 mov ecx, dword_402000 .text:00401137 mov [esp+28h+var_24], eax .text:0040113B mov [esp+28h+var_20], edx .text:0040113F mov [esp+28h+var_1C], ecx .text:00401143 mov [esp+28h+var_28], offset dword_404004 .text:0040114A call __getmainargs .text:0040114F mov eax, ds:dword_404010 .text:00401154 test eax, eax .text:00401156 jz short loc_4011B0 .text:00401158 mov dword_402010, eax .text:0040115D mov edx, ds:_iob .text:00401163 test edx, edx .text:00401165 jnz loc_4011F6 </code></pre> <hr> <pre><code>.text:004012E0 sub_4012E0 proc near ; CODE XREF: sub_401000+C6p .text:004012E0 ; sub_401100+19p .text:004012E0 push ebp .text:004012E1 mov ebp, esp .text:004012E3 fninit .text:004012E5 pop ebp .text:004012E6 retn .text:004012E6 sub_4012E0 endp </code></pre>
 

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