Reverse Engineering for Beginners

(avery) #1

CHAPTER 35. TEMPERATURE CONVERTING CHAPTER 35. TEMPERATURE CONVERTING


push OFFSET $SG4041 ; 'Error while parsing your input'
call esi ; call printf()
add esp, 4
push 0
call DWORD PTR impexit
$LN2@main:
fld QWORD PTR _fahr$[esp+12]
fsub QWORD PTR real@4040000000000000 ; 32
fmul QWORD PTR
real@4014000000000000 ; 5
fdiv QWORD PTR real@4022000000000000 ; 9
fld QWORD PTR
real@c071100000000000 ; -273
fcomp ST(1)
fnstsw ax
test ah, 65 ; 00000041H
jne SHORT $LN1@main
push OFFSET $SG4043 ; 'Error: incorrect temperature!'
fstp ST(0)
call esi ; call printf()
add esp, 4
push 0
call DWORD PTR impexit
$LN1@main:
sub esp, 8
fstp QWORD PTR [esp]
push OFFSET $SG4044 ; 'Celsius: %lf'
call esi
add esp, 12 ; 0000000cH
; return 0 - by C99 standard
xor eax, eax
pop esi
add esp, 8
ret 0
$LN10@main:
_main ENDP


...but MSVC 2012 usesSIMDinstructions instead:


Listing 35.3: Optimizing MSVC 2010 x86

$SG4228 DB 'Enter temperature in Fahrenheit:', 0aH, 00H
$SG4230 DB '%lf', 00H
$SG4231 DB 'Error while parsing your input', 0aH, 00H
$SG4233 DB 'Error: incorrect temperature!', 0aH, 00H
$SG4234 DB 'Celsius: %lf', 0aH, 00H
real@c071100000000000 DQ 0c071100000000000r ; -273
real@4040000000000000 DQ 04040000000000000r ; 32
real@4022000000000000 DQ 04022000000000000r ; 9
real@4014000000000000 DQ 04014000000000000r ; 5


_fahr$ = -8 ; size = 8
_main PROC
sub esp, 8
push esi
mov esi, DWORD PTR impprintf
push OFFSET $SG4228 ; 'Enter temperature in Fahrenheit:'
call esi ; call printf()
lea eax, DWORD PTR _fahr$[esp+16]
push eax
push OFFSET $SG4230 ; '%lf'
call DWORD PTR impscanf
add esp, 12 ; 0000000cH
cmp eax, 1
je SHORT $LN2@main
push OFFSET $SG4231 ; 'Error while parsing your input'
call esi ; call printf()
add esp, 4
push 0
call DWORD PTR impexit
$LN9@main:
$LN2@main:
movsd xmm1, QWORD PTR _fahr$[esp+12]

Free download pdf