c++/ assembly recursive troubles

Reply

Join Date: May 2007
Posts: 3
Reputation: Assemblyn00b is an unknown quantity at this point 
Solved Threads: 0
Assemblyn00b Assemblyn00b is offline Offline
Newbie Poster

c++/ assembly recursive troubles

 
0
  #1
May 6th, 2007
Basically I have to take in N and bring it to power of K so N^K
i have the c++
i have the basic assembly
but something is wrong the math doesn't come out right

.386p
.model flat
.code
_func proc near
push ebp
mov ebp, esp
mov eax, [ebp+12]
mov ecx, [ebp+8]
cmp ecx, 0
ja L1
jmp L2
L1:
dec ecx
push eax
push ecx
CALL _func
add esp, 8
mov ebx, [ebp+8]
mul ebx
L2:
pop ebp
ret
_func endp
END

is what i have..can anyone please help
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: c++/ assembly recursive troubles

 
0
  #2
May 7th, 2007
You would appear to have a program which goes something like:


_func
;push registers
;load eax and ecx
;if ecx > 0
; decrement ecx
; push registers
; jump back up to _func

;else
; pop ebp
ret

Chewing up large amounts of stack as it goes. So far as I can see the following lines never get executed:
mov ebx, [ebp+8]
mul ebx
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 3
Reputation: Assemblyn00b is an unknown quantity at this point 
Solved Threads: 0
Assemblyn00b Assemblyn00b is offline Offline
Newbie Poster

Re: c++/ assembly recursive troubles

 
0
  #3
May 7th, 2007
.386p
.model flat
.code
_func proc near
mov edx, 0
push ebp
mov ebp, esp
mov eax, [ebp+12]
mov ecx, [ebp+8]
cmp ecx, 0
ja L1
mov eax, 1
jmp L2
L1:
dec ecx
push eax
push ecx
CALL _func
add esp, 8
mov ebx, [ebp+12]
mul ebx
L2:
pop ebp
ret
_func endp
END


is my modified code.. .works sometimes but 52^0 comes out 0 and 6^4 comes out to 8^4
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC