Well.. after days of troubleshooting.. I got me' program to work!!!
My main problems were:
the edx register needs to be cleared when using the 'div' operator.. because division uses both the edx:eax registers as the dividend. setting edx to zero will eliminate garbage data from any previous operations using this register.
also, I used a different approach to array indexing.. instead of continually manipulating the array offset in the esi register, I used a style of array indexing.. that resembles more of what you would see in a high-level language:
where the ebx is a dedicated array counter. This style is better, because one does not have to increment an array pointer by units of 4 (in a 32-bit array).. there is now a 1:1 relationship between the array counter and the array address.. (just like with a high level language )
Anywhoo.. Here is the finished product Let me know what you think!! Feedback = good
i'll also be putting this up on flashdaddy.com (thanks axon)
TITLE Chinchilla Madness
;this program will calculate population growth of
;the wild chinchilla over a 14 year span
prompt1 BYTE "Enter semi-annual rate of chinchilla offspring: ",0
prompt2 BYTE "Total number of chinchillas at a rate of ",0
prompt3 BYTE " chinchillas semi-annually is: ",0
array DWORD 28 DUP(?) ;14 years.. semi-annually = 28
loopcount DWORD ?
rate DWORD ?
mov esi, 0
mov esi, OFFSET array
mov ecx, 26
mov edx, OFFSET prompt1
mov rate, eax
mov array, 2 ;first and second elements will always
mov array, 2 ;be set to '2' (representing the parents)
mov ebx, 2 ;ebx will be my dedicated array counter (starting on 3rd element)
;This algorithm represents, "go back two elements from the
;current element, and divide it's contents by '2'.. then
;multiply the quotient by the user entered rate.. then
;add to the contents in [current element - 1]... and put
;the final result in [current element]
mov loopcount, ecx ;free up ecx for use in calculations
mov eax, array[ebx-2] ;"two elements back from current element" mov to eax in preperation for divide
mov ecx, 2 ;use ecx as register operand for 'mul' and 'div'
mov edx, 0 ;clear edx to perform low-end division
div ecx ;divide eax/2 and store quotient into eax
mov edx, 0 ;throw away any remainder
mov ecx, rate ;move rate to ecx as a register operand for use with 'mul'
mul ecx ;multiply answer (in eax) by rate and store in edx:eax
add eax, array[ebx-1] ;"add result to [current element - 1]"
mov array[ebx], eax ;store final result into current element
mov ecx, loopcount ;restore ecx as a loop counter
inc ebx ;increment the array to next element
mov edx, OFFSET prompt2
mov eax, rate
mov edx, OFFSET prompt3
mov eax, array[ebx]
For all of you who ever wanted to know the number of chinchillas you would have after 14 years.