.386
.model small,C
.data
.code
AdjustedSum proc uses ebx ecx esi edi numbers:ptr, used:dword ;int AdjustedSum(int numbers[], int used);{
mov ebx, numbers ;move base address of array in ebx
mov eax,0 ; int AdjustedSum = 0;
AdjustedSum_if1: ; if(used <= 2)
cmp used, 2
jg AdjustedSum_if1_end
ret ; return AdjustedSum;
AdjustedSum_if1_end:
mov esi, [ebx] ; int max = numbers[0];
mov edi,[ebx] ; int min = numbers[0];
mov ecx, 0 ; int i = 0;
AdjustedSum_while1: ; while( i < used) {
cmp ecx, used
jge AdjustedSum_while1_end
AdjustedSum_if2: ; if(max < numbers[i] )
cmp esi, [ebx+4*ecx]
jge AdjustedSum_if2_end
mov esi, [ebx+4*ecx] ; max = numbers[i];
AdjustedSum_if2_end:
AdjustedSum_if3: ; if(min > numbers[i])
cmp edi, [ebx+4*ecx]
jle AdjustedSum_if3_end
mov edi, [ebx+4*ecx] ; min = numbers[i];
AdjustedSum_if3_end:
add ecx, 1 ; i++;
AdjustedSum_while1_end: ; }
mov ecx, 0 ; int j = 0;
AdjustedSum_while2: ; while(j < used){
cmp ecx,used
jge AdjustedSum_while2_end
add eax, [ebx+4*ecx] ; AdjustedSum = AdjustedSum + numbers[j];
add ecx,1 ;j++;
AdjustedSum_while2_end: ; }
sub eax,edi ; AdjustedSum = AdjustedSum - min;
sub eax,esi ; AdjustedSum = AdjustedSum - max;
ret ; return AdjustedSum;
AdjustedSum endp ;}
end
views:
78answers:
1
+1
A:
AdjustedSum_if1: ; if(used numbers[i]) cmp edi, [ebx+4*ecx]
What's the value of ecx
the first time through here?
Anon.
2009-12-08 03:56:53
I uses ecx as my counter variable for the index
Zerobu
2009-12-08 03:59:17
Alright. So, walking through the code by hand, what is its value when it first reaches that point?
Anon.
2009-12-08 04:01:26