;============================================================================== ;file :add.asm ;author :Andre Long ;due :April 24, 2006 ;description :This program will use arrays to calculate fibonacci numbers ;============================================================================== ;Procedures To INCLUDE Pcmac.inc ;macros EXTRN NEWLINE:FAR ;display a new line EXTRN GETDEC$:FAR ;gets 16-bit decimal number EXTRN PUTDEC$:FAR ;display 16-bit decimal number ;============================================================================== .MODEL SMALL .586 .STACK 1000h ;============================================================================== .DATA Aray DB 72 DUP (0) Bray DB 72 DUP (0) Cray DB 72 DUP (0) carryN DB 0 endPos DW 71 nextPos DW 0 counterX DW 0 N DW ? mess1 DB 'Enter the nth fibonacci number you would like to find ', '$' mess2 DB ' nth fibonacci number is', '$' mess3 DB ' Overflow Occured!!! ', '$' ;============================================================================== .CODE addFib proc _Begin sPutStr mess1 call getdec$ mov N, ax mov ax, 0 mov bx, 0 mov si, endPos mov [Aray + si], 1 mov [Bray + si], 0 setBlue: mov cx, N blue: cmp counterX, cx jb red jmp byeOuterLoop red: cmp si, 0 jl green mov al, [Aray + si] mov bl, [Bray + si] add al, bl add al, carryN cmp al, 9 jbe noCarry jmp yesCarry noCarry: mov carryN, 0 mov [Cray + si], al dec si jmp red yesCarry: mov carryN, 1 sub al, 10 mov [Cray + si], al dec si jmp red green: mov si, endPos green2: cmp si, 0 jl green3 mov dl, [Bray + si] ; move BX into AX mov [Aray + si], dl dec si jmp green2 green3: mov si, endPos green4: cmp si, 0 jl doneInner mov dl, [Cray + si] ; CX into BX mov [Bray + si], dl dec si jmp green4 doneInner: inc counterX mov si, endPos jmp blue byeOuterLoop: cmp carryN, 1 jae Ov jmp resume resume: ;mov ax, N ;call putdec$ sPutStr mess2 call newline resume2: cmp nextPos, 72 jb see jmp go see: mov di, nextPos ;display Cray array mov al, [Cray + di] call putdec$ inc nextPos mov di, nextPos mov al, [Cray + di] jmp resume2 Ov: sPutStr mess3 go: _Exit addFib endp end addFib