Disassembly
Set up program stack frame
1155: 55 push rbp
1156: 48 89 e5 mov rbp,rsp
1159: 48 83 ec 10 sub rsp,0x10
Setup inital variables
115d: c7 45 fc 64 00 00 00 mov DWORD PTR [rbp-0x4],0x64 ; 0x64 integer into stack (firstNumber)
1164: c7 45 f8 0e 00 00 00 mov DWORD PTR [rbp-0x8],0xe ; 0xe integer into stack (secondNumber)
116b: c7 45 f0 00 00 00 00 mov DWORD PTR [rbp-0x10],0x0 ; integer variable that is used for scanf input
1172: c7 45 f4 00 00 00 00 mov DWORD PTR [rbp-0xc],0x0 ; integer used to generated number
DWORD PTR ---> move 0 to the 32 bits of the stack in a place which
starts with the adress rbp-4.
this is our`int x = 100`
Print Welcome
1179: 48 8d 3d 88 0e 00 00 lea rdi,[rip+0xe88] ; "Welcome to the wonderful world of assembly!" to rdi
1180: e8 ab fe ff ff call 1030 <puts@plt> ; print "Welcome to the wonderful world of assembly!"
Ask for number
1185: 48 8d 3d a8 0e 00 00 lea rdi,[rip+0xea8] ; "Qual o numero magico? " to rdi
118c: b8 00 00 00 00 mov eax,0x0 ; ???
1191: e8 aa fe ff ff call 1040 <printf@plt> ; print "Qual o numero magico? "
Get number with scanf
1196: 48 8d 45 f0 lea rax,[rbp-0x10] ; move start of buffer for scanf to write into to rax
119a: 48 89 c6 mov rsi,rax ; move start of buffer from rax to rsi
119d: 48 8d 3d a7 0e 00 00 lea rdi,[rip+0xea7] ; move "%d" input format into rdi
11a4: b8 00 00 00 00 mov eax,0x0 ; ???
11a9: e8 a2 fe ff ff call 1050 <__isoc99_scanf@plt> ; call scanf scanf("%d", rbp-0x10);
(((firstNumber + firstNumber) + firstNumber) + secondNumber) / firstNumber
11ae: 8b 55 fc mov edx,DWORD PTR [rbp-0x4] ; 0x64 into edx
11b1: 89 d0 mov eax,edx ; 0x64 from edx into eax
11b3: 01 c0 add eax,eax ; 0x64 + 0x64 = 0xC8 eax = 0xC8
11b5: 01 c2 add edx,eax ; 0x64 + 0xC8 = 0x12C rdx = 0x12c
11b7: 8b 45 f8 mov eax,DWORD PTR [rbp-0x8] ; 0xe from stack into eax
11ba: 01 d0 add eax,edx ; 0xe + 0x12C = 0x13a rax = 0x13a
11bc: 99 cdq ; extend rax into rdx, next instruction will do signed divide RDX:RAX by r/m64
11bd: f7 7d fc idiv DWORD PTR [rbp-0x4] ; divide 0x13a by 0x64, store result in rax. RAX = 3
11c0: 89 45 f4 mov DWORD PTR [rbp-0xc],eax ; move division result into stack at rbp-0xc
Compare generated number with user entered number, and print if correct or not
11c3: 8b 45 f0 mov eax,DWORD PTR [rbp-0x10] ; move user entered number into eax
11c6: 39 45 f4 cmp DWORD PTR [rbp-0xc],eax ; compare generated number (3) and user entered number
Print Success
11c9: 75 0e jne 11d9 <main+0x84> ; conditional jump usually followed by a compare statement
11cb: 48 8d 3d 7c 0e 00 00 lea rdi,[rip+0xe7c] ; load effective address of "Essa eh a sua flag!" into rdi
11d2: e8 59 fe ff ff call 1030 <puts@plt> ; print "Essa eh a sua flag!"
11d7: eb 0c jmp 11e5 <main+0x90>
Print Error Message
11d9: 48 8d 3d 82 0e 00 00 lea rdi,[rip+0xe82] ; load "Try harder..." into rdi
11e0: e8 4b fe ff ff call 1030 <puts@plt> ; print "Try harder..."
11e5: b8 00 00 00 00 mov eax,0x0 ; ???
Exit Program
11ea: c9 leave
11eb: c3 ret
11ec: 0f 1f 40 00 nop DWORD PTR [rax+0x0]
Last updated