Who To Write From C++ Code To Assembly code?
HI
I need help with my homework I got this code and have to write from c++ to assembly code
I try to do it but the answer is always a symbol ?????
C++ code version:
Main()
{
int I, J, K, L;
I=-4;
J=30;
K=(4*I*J)+(I+5*J)+1;
L=K/I;
I=I+1;
J=J-I-1;
}
Comments
Here's a highly optimized version of that
public _Main
_Main:
ret
okay so here is a less optimal version
public _Main
_Main:
; I = -4, J = 30
mov ebx, -4
mov ecx, 30
; EAX = I * J
mov eax, ebx
imul eax, ecx
; EDX = 5*J + I
lea edx, [ecx+4*ecx]
add edx, ecx
; EAX = 4 * (I*J) + (I+5*J) + 1 = K
lea eax, [edx + 4*eax + 1]
push eax
xor edx, edx
; EAX = K / I, EDX = K % I
idiv eax, ebx
pop edx
; If we do the subtraction now, we don't need the additional decrement
sub ecx, ebx
; I = I + 1
inc ebx
ret