News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

recursive functions

Started by imadhx30, February 03, 2014, 04:03:17 AM

Previous topic - Next topic

imadhx30

give the recursive functions of this function
n1^0*n2^p+...................+n1^p*n2^0
fonc proc ,n1:DWORD,n2:DWORD,p:DWORD
mov ecx,1
mov esi,p
repete:
cmp i,esi
ja fin
mov eax,ecx
mov ebx,n2
mul ebx
mov ecx,eax
inc i
jmp repete
fin:
mov eax,ecx
repete1:
cmp j,esi
ja fin1
mov ebx,n2
div ebx
mov ebx,n1
mul ebx
add ecx,eax
inc j
jmp repete1
fin1:
mov eax,ecx
ret
fonc endp
end start

K_F

I was fiddling with some recursive stuff the other day... It's all about complexity and speed...

I made a nice proc that worked only with local vars and parameters, but it was computationally intensive.
I found I could do the same thing with external variables a gazillion times faster that worked in simple loops.

It depends on the 'depth of recursiveness' that you want to go :-
- If the depth is unknown go the complex route - it's slower, but watch your stack
- For know max depth, go loops and external variables = much faster and easier to control.

:)
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

hutch--

Recursion is at its most useful when you need to store each iteration's local data on the stack so that you can either recurse above it or return to it from a higher recursive iteration. Its often used to move up and down a dynamically created tree, a quick sort is one example. If you do not need to store local variables then as Van suggested, a purely iterative approach using global variables is usually a lot faster as it does not have the stack overhead. It is usually a lot less memory intensive as well.

habran

Cod-Father