.MODEL small
.STACK 100h
.DATA
FibVetor DB 0,0,0,0,0,13,10,'$'
Tam DB 5
.CODE
mov cx,@data
mov ds,cx ;set DS to point to the data segment
mov ax,5
CALL FIB
add bx,48
mov [FibVetor],bl
mov ah,9 ;DOS print string function
mov dx,OFFSET FibVetor ;point to "Hello, world"
int 21h ;display "Hello, world"
mov ah,4ch ;DOS terminate program function
int 21h ;terminate the program
FIB proc near
push ax ;empilha ax
cmp ax,1 ;compara ax com 1
jz LABEL_IF ;se for verdadeiro vai para label if
cmp ax,2 ;se n for 1 compara com 2
jz LABEL_IF ;se for 0 pula para label_if
dec ax ;decrementa ax
CALL FIB ;chama fib recursivamente
mov cx,bx ;poem o ret da funcao em cx
dec ax ;dec ax
CALL FIB ;chama fib recursivamente
add bx,cx ;soma bx com cx o retorno esta em bx aogra tem fib(n-1)+fib(n-2)
jmp FIB_END ;pula para FIB_END;
LABEL_IF:
mov bx,1
jmp FIB_END
FIB_END:
pop ax
ret
ENDP
END