Home > other >  Before the Fibonacci sequence assembly recursive o N items!
Before the Fibonacci sequence assembly recursive o N items!

Time:09-18

Head all big or not
It's really difficult to assembly, sprout new think

Such as input output 1 1 2 3 4 these four


Who teach me to use recursion to solve

CodePudding user response:

Is how to calculate not, still don't know how to use the assembly said?
How to calculate, should be simple, after all, the book should be functional is simple, it is not difficult to understand,
Assembly said, it is similar to a high-level language, only available instruction/statements and on grammar, ideas are the same,

CodePudding user response:

reference 1/f, zara's reply:
is how to calculate won't, or don't know how to use assembly said?
How to calculate, should be simple, after all, the book should be functional is simple, it is not difficult to understand,
Assembly said, it is similar to a high-level language, only available instruction/statements and on grammar, ideas are the same,
no example of the book

CodePudding user response:

Algorithm, is very simple, n<=1 fibo (n)=1, n>=2 fibo (n)=fibo (n - 1) + fibo (n - 2),
N in cx fibo (n) returns in ax, so using a recursive method, most of the operation is redundant, isn't it?
 fibo2 proc 
Push dx
Cx, CMP 1
Jbe l_le1
L_gt1:
Dec cx
Call fibo2
Mov dx, ax
Dec cx
Call fibo2
The add ax, dx
Cx, add 2
JMP l_ret
L_le1:
Mov ax, 1
L_ret:
Pop dx
Ret
Fibo2 endp

CodePudding user response:

Zara
reference 3 floor response:
algorithm, very simple, n<=1 fibo (n)=1, n>=2 fibo (n)=fibo (n - 1) + fibo (n - 2),
N in cx fibo (n) returns in ax, so using a recursive method, most of the operation is redundant, isn't it?
 fibo2 proc 
Push dx
Cx, CMP 1
Jbe l_le1
L_gt1:
Dec cx
Call fibo2
Mov dx, ax
Dec cx
Call fibo2
The add ax, dx
Cx, add 2
JMP l_ret
L_le1:
Mov ax, 1
L_ret:
Pop dx
Ret
Fibo2 endp
bosses I make up the output of the reference to your application after his former N items always garbled

CodePudding user response:

Gibberish, not convert values to display characters, or conversion errors? Breakpoint stop before display, view output value is to look at, back for a walk, and see what went wrong
  • Related