Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   Converting 16bit Code To 32bit Code (http://www.programmingforums.org/showthread.php?t=1531)

reynard082 Dec 13th, 2004 4:15 PM

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;
        }


saxman Dec 25th, 2004 6:59 PM

Can you post the original 16-bit code?

liquidsilver Mar 11th, 2005 4:02 PM

Maybe you cleared ax and not eax?

PS: In your code change Postitive > Positive

Christian_Rosenkreuz_777 Mar 11th, 2005 5:53 PM

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.

liquidsilver Mar 12th, 2005 1:36 PM

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.


All times are GMT -5. The time now is 4:09 AM.

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