Assembly code snippets
Details
Title | Fibonacci Numbers (macro nesting) |
---|---|
Author | bitRAKE |
Submitted by: | bitRAKE |
Date added: | 2002-02-17 21:05:05 |
Date modified: | 2002-02-17 21:05:05 |
Comments
;; Recursion is self-explainatory...
;; These macros demostrate nesting limits and how to work around them
Snippet
fib MACRO y:REQ
IF y LE 1
EXITM <1>
ELSE
EXITM %(fib(y - 2) + fib(y - 1))
ENDIF
ENDM
i TEXTEQU fib(20)
%ECHO i
;;---------------------------
fib MACRO y:REQ
LOCAL a,b,e
IF y LE 1
EXITM <1>
ELSE
e = y
a = fib(e/2)
b = fib(e/2 - 1)
IF (y MOD 2) EQ 1
EXITM %(a * (a + 2 * b))
ELSE
EXITM %(a*a + b*b)
ENDIF
ENDIF
ENDM
i TEXTEQU fib(46)
%ECHO i
IF y LE 1
EXITM <1>
ELSE
EXITM %(fib(y - 2) + fib(y - 1))
ENDIF
ENDM
i TEXTEQU fib(20)
%ECHO i
;;---------------------------
fib MACRO y:REQ
LOCAL a,b,e
IF y LE 1
EXITM <1>
ELSE
e = y
a = fib(e/2)
b = fib(e/2 - 1)
IF (y MOD 2) EQ 1
EXITM %(a * (a + 2 * b))
ELSE
EXITM %(a*a + b*b)
ENDIF
ENDIF
ENDM
i TEXTEQU fib(46)
%ECHO i