Ladies and Gents:

These forums are now closed and registration disabled.

Please join us at our new forum on Proboards. Our hope is that these new forums are more stable, provide more and better features, and allow continuation of the project forums in a safer, more secure, long term environment.


--The ME3Explorer Team


Coder-centric area for programming advice and questions.


Postby WarrantyVoider » 31 Mar 2013, 22:38

I thought I should start this here, at least for me to remember. Here I took a simple C program, compiled it with TinyC compiler and disassembled it with IDA Pro, so you might get an idea what an CPU all does for some simple operations, input and bugreports are welcome^^ if anyone wants to share his knowledge too , please post here

get tinyC here

create a file called hello.c

#include <stdio.h>
int x = 24;
x *= 2;
float f = 24;
f *= x;
printf("Hello world!\nX = %i\n F = %f",x,f);

now you can compile it with these commands

D:\test>tcc -c hello.c -o hello.o -v 
tcc version 0.9.24
-> hello.c
<- hello.o

D:\test>tcc hello.o -o hello.exe -v
tcc version 0.9.24
-> hello.o
<- hello.exe (1536 bytes)

now I went through the asm code and commented out what does what, I help that clears a few things up^^

.text:00401000 Main__          proc near               ; CODE XREF: start+5E
.text:00401000 var_XasInt = dword ptr -0Ch
.text:00401000 var_F = dword ptr -8
.text:00401000 var_X = dword ptr -4
.text:00401000 push ebp
.text:00401001 mov ebp, esp
.text:00401003 sub esp, 8 ; two vars (x and f) = 2x 4 byte pointer esp->VarF
.text:00401009 nop ; filler
.text:0040100A mov eax, 18h ; X = 24
.text:0040100F mov [ebp+var_X], eax ; store
.text:00401012 mov eax, [ebp+var_X] ; load
.text:00401015 shl eax, 1 ; X *= 2
.text:00401018 mov [ebp+var_X], eax ; store
.text:0040101B fld flt_402000 ; F = 24 stored in FPU SP(0) Stack
.text:00401021 fst [ebp+var_F] ; store SP(0) in VarF
.text:00401024 fstp st(1) ; copy SP(0) (VarF) to SP(1)
.text:00401026 mov eax, [ebp+var_X] ; push x to stack
.text:00401029 push eax ; push x as int on stack, esp->VarXAsInt
.text:0040102A fild [esp+0Ch+var_XasInt] ; load XAsInt as float to stack sp(0)
.text:0040102D add esp, 4 ; correct stack pointer after push, esp->VarF
.text:00401030 fmul [ebp+var_F] ; XAsInt in SP(0) * VarF stored in SP(0)
.text:00401033 fst [ebp+var_F] ; save to VarF
.text:00401036 fstp st(1) ; copy SP(0) (VarF) to SP(1)
.text:00401038 fld [ebp+var_F] ; load VarF to SP(0)
.text:0040103B sub esp, 8 ; point esp to next free offset after VarXAsInt on stack
.text:00401041 fstp qword ptr [esp+0] ; Arg2 from SP(0) on stack
.text:00401045 mov eax, [ebp+var_X] ; load Arg1
.text:00401048 push eax ; Arg1
.text:00401049 mov eax, offset Format ; "Hello world!\nX = %i\n F = %f"
.text:0040104E push eax ; Format
.text:0040104F call printf
.text:00401054 add esp, 10h
.text:00401057 leave
.text:00401058 retn
.text:00401058 Main__ endp

greetz WV
always backup your files!
mess with the best or die like the rest!
"I tried everything!" - "mkay, please list that..." ; please dont pm me for help, we have a help section

WarrantyVoider has been thanked by:
User avatar
Posts: 2270
Joined: 22 Aug 2012, 11:33
Has thanked: 480 time
Have thanks: 626 time

Re: Disassembling

Postby Renmiri » 03 Apr 2013, 08:15

This reminds of Uni.. Can almost hear the fuzzball tables at the rec center where I frittered away my study time ;)

Glad you are paying more attention than I did! ^^
Posts: 207
Joined: 31 Aug 2012, 20:42
Has thanked: 141 time
Have thanks: 37 time

Return to Coders' Help

Who is online

Users browsing this forum: No registered users and 0 guests