Tuesday, November 11, 2014

I'm looking for someone really small...................................

                              We're going to talk about how to find the smallest guy in a crowd. I tweaked my program from the last post,so now instead of finding out how many of the numbers are 8's,we're going to find out which one of the numbers is the smallest.

Here's the program:

The C++ part:

extern "C" void doit();

void main()

And the assembly part:

.model flat, c
.stack 100h

 myNumbers dword 7,3,8,2,2,9,8,5,7,4,8,3,8,1,8,7,4,8


doit proc
xor eax,eax
xor ecx,ecx
mov ebx,myNumbers[eax]
add eax,4
mov ecx,myNumbers[eax]
cmp ecx,ebx
jl switcheroo
cmp eax,68
jle again
mov ebx,ecx
jmp back

doit endp


             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