Implement the following C++ expression in assembly language, using 32-bit signed operands:
val1 = (val2/val3)*(val1 – val2)
xor edx, edx ; edx = 0 befor imul
mov eax, val2 ; eax = val2
mov ebx, val3 ; ebx = val3
idiv ebx ; eax = val2/val3
push eax ; save eax in stack
mov ebx, val1 ; ebx = val1
sub ebx, val2 ; ebx = val1 – val2
pop eax ; restore eax = (val2/val3)
imul ebx ; eax = (val2/val3)*( val1 – val2)
mov var1, eax ; save new val1
Comments
Leave a comment