Here's the program:
The C++ part:
extern "C" void doit();
void main()
{
doit();
}
And the assembly part:
.586
.model flat, c
.stack 100h
.data
myNumbers dword 7,3,8,2,2,9,8,5,7,4,8,3,8,1,8,7,4,8
.code
doit proc
xor eax,eax
xor ecx,ecx
mov ebx,myNumbers[eax]
again:
add eax,4
mov ecx,myNumbers[eax]
cmp ecx,ebx
jl switcheroo
back:
cmp eax,68
jle again
ret
switcheroo:
mov ebx,ecx
jmp back
doit endp
end
So get all that typed in and I'll explain how it works.
This is how it works,just like the program from the last post we xor eax by eax,and ecx by ecx,and also we move myNumbers into ebx,except we only do that once because of the again. Then as always we add 4 to eax so that we can access the next number of myNumbers,except not because we want to place the next number of myNumbers in ebx,we want to place it in ecx,and here's why.
We take the next number of myNumbers and compare it to the number currently in ebx and if it is smaller than the number currently in ebx then we jump to switcheroo. In switcheroo we move the number currently in ecx into ebx so that we always have the smallest number we've seen so far in ebx. Then we jump to back compare eax to 68 and if it is less than or equal to 68 we jump back to again.
WELL TTFN TA TA FOR NOW!!!!
No comments:
Post a Comment