|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: |
#include <iostream>
using namespace std;
int fib(int num)
{
if (num < 1) /*if number is less than or equal to 1*/
{
return 1; /* return number */
}
else
{
return 2*(fib(num-1))+fib(num-2); /* return fibonacci formula */
}
}
void main()
{
int num; /* The fibonacci number selected */
cout << "Which Fibonacci number? ";
cin >> num; /* input */
cout<<"The number is: " << fib(num) << endl; /*outputs the fibonacci sum*/
}
BR main
num: .EQUATE 0 ;formal paramter #2,d
;
;*****************************main()
main: STRO msg1,d ;cout<<"Which Fibonacci Number? "
DECI num,d ;cin >> num
CHARO '\n',i ; << endl
STRO msg2,d ;cout<< "The number is: "
;STA -2,s
;SUBSP 2,i
CALL fib
;
;******************** int fib (int num)
num: .EQUATE 0 ;formal paramter #2h
fib: SUBSP 2,i ;allocate #num
if: LDA num,d ;if (num < 1)
BRLE else
then: LDA 1,i ; return 1
STA retVal,s
RET2
else: ASLA ; 2*
LDA num,d
SUBA 1,i ;(num-1)
STA num,d
ADDA num,d ; +
LDA num,d
SUBA 2,i ;(num-2)
STA num,d
RET2 ;deallocate #num, pop retAdd
BR endIf
endIf: STOP
msg1: .ASCII "Which Fibonacci Number? \x00"
msg2: .ASCII "The number is: \x00"
.END
|
Advertisement
| Hall of Fame |