Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 13th, 2004, 3:15 PM   #1
reynard082
Newbie
 
Join Date: Dec 2004
Posts: 1
Rep Power: 0 reynard082 is on a distinguished road
I have to create a assembly program that does the Fibonacci series using recursion. I wrote the program in 16bit code using a subproc for the fibonacci recursion and debugged it until it works. Then I converted the code to 32bit code by adding the E's to the registers and adding a few lines to the top. I also doubled the pointer addresses that I use. This program also has to be complied with C++ code.

Like I said when the program runs in 16-bit mode, everything work fine. But when it's converted and complied w/ C++ code, when I input 1, it works fine. However when I put in 2 I get 4551668. However when I put in 3, i get 4551669. If i substract 4551668 from whatever number I get, it works. So here's my question - where does the 4551668 come from? Is there something i'm not taking into consideration when i'm debugging it?

any suggestion would be extremely helpful...

thanks
Matt

here's my code...
.386p
.model flat
.code

_fib proc near

	push ebp
	mov ebp,esp
	mov eax,[ebp+8]
  
	cmp eax,1
	je L2A
	cmp eax,0
	je L2B
	
	L1:

;fib(n-2)
	
                sub eax,2
 push eax
 CALL _fib 

 add esp,4

	;fib(n-1)

 mov eax,[ebp+8];reset N value
	
                sub eax,1
 push eax
 CALL _fib 

 add esp,4
 mov eax,edx

 jmp L2B
	
	L2A:
                add edx,1
 pop ebp
 jmp L2D
 
	L2B:
 pop ebp
 
	L2D:
 ret

_fib endp
END
my C++ code
#include <iostream>
using namespace std;

extern "C" unsigned int fib(int);

int main ()
	{
	int N;
	unsigned int result;

        cout<<"Enter a Postitive Integer: ";
	cin>>N;

        result=fib(N);
        cout<<N<<" fib number -> "<<result<<endl;

        cout<<"Enter a Postitive Integer: ";
	cin>>N;
        }
  
	return 0;
	}
reynard082 is offline   Reply With Quote
Old Dec 25th, 2004, 5:59 PM   #2
saxman
Newbie
 
Join Date: Dec 2004
Posts: 7
Rep Power: 0 saxman is on a distinguished road
Can you post the original 16-bit code?
saxman is offline   Reply With Quote
Old Mar 11th, 2005, 3:02 PM   #3
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Maybe you cleared ax and not eax?

PS: In your code change Postitive > Positive
__________________
Small is beautiful
liquidsilver is offline   Reply With Quote
Old Mar 11th, 2005, 4:53 PM   #4
Christian_Rosenkreuz_777
Newbie
 
Join Date: Feb 2005
Location: Charlottesville, VA (rated #1 place to live)
Posts: 25
Rep Power: 0 Christian_Rosenkreuz_777 is on a distinguished road
They're compatible. If you want to take advantage of 32-bit registers, instead of ax write eax. I use 16-bit though because i'm used to it and I haven't needed more room.
__________________
Cavear Emptor
Christian_Rosenkreuz_777 is offline   Reply With Quote
Old Mar 12th, 2005, 12:36 PM   #5
liquidsilver
Newbie
 
liquidsilver's Avatar
 
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0 liquidsilver is on a distinguished road
Christian_Rosenkreuz_777: I thought that's what he did:
Quote:
Then I converted the code to 32bit code by adding the E's to the registers and adding a few lines to the top.
__________________
Small is beautiful
liquidsilver is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC