[EXERCISE 0007] Simple math operations

Ah, math. What a beautiful discipline. Lots of math is used within application development. Understandable in C++ might be problematic in assembly code. This exercise is not a problem at all, just some few math lines which are not complicated. Anyway, it is very important that you start playing such little math game if we later dig into cryptographic schemes. So tell me: what is this code doing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.text:00401000 _main proc near
.text:00401000
.text:00401000 var_18= dword ptr -18h
.text:00401000 var_14= dword ptr -14h
.text:00401000 var_10= qword ptr -10h
.text:00401000 var_8= dword ptr -8
.text:00401000 var_4= dword ptr -4
.text:00401000 argc= dword ptr  8
.text:00401000 argv= dword ptr  0Ch
.text:00401000 envp= dword ptr  10h
.text:00401000
.text:00401000 push    ebp
.text:00401001 mov     ebp, esp
.text:00401003 sub     esp, 18h
.text:00401006 mov     [ebp+var_4], 5
.text:0040100D mov     [ebp+var_8], 6
.text:00401014 mov     eax, [ebp+var_4]
.text:00401017 add     eax, [ebp+var_8]
.text:0040101A mov     [ebp+var_14], eax
.text:0040101D mov     ecx, [ebp+var_8]
.text:00401020 sub     ecx, [ebp+var_4]
.text:00401023 mov     [ebp+var_14], ecx
.text:00401026 mov     edx, [ebp+var_4]
.text:00401029 imul    edx, [ebp+var_8]
.text:0040102D mov     [ebp+var_14], edx
.text:00401030 mov     eax, [ebp+var_4]
.text:00401033 cdq
.text:00401034 idiv    [ebp+var_8]
.text:00401037 mov     [ebp+var_18], eax
.text:0040103A fild    [ebp+var_18]
.text:0040103D fstp    [ebp+var_10]
.text:00401040 xor     eax, eax
.text:00401042 mov     esp, ebp
.text:00401044 pop     ebp
.text:00401045 retn
.text:00401045 _main endp