944,095 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1752
  • Assembly RSS
May 6th, 2007
0

c++/ assembly recursive troubles

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Assemblyn00b is offline Offline
3 posts
since May 2007
May 7th, 2007
0

Re: c++/ assembly recursive troubles

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
Reputation Points: 14
Solved Threads: 4
Junior Poster
mathematician is offline Offline
149 posts
since Nov 2006
May 7th, 2007
0

Re: c++/ assembly recursive troubles

.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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Assemblyn00b is offline Offline
3 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Printing Uppercase Characters
Next Thread in Assembly Forum Timeline: How could I break an infinite loop??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC