News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

fibonacci program help

Started by vinnyvin_m, May 14, 2006, 10:57:09 PM

Previous topic - Next topic

vinnyvin_m

I'm having some trouble writing a fibonacci program. I'm new at this and obviously don't fully understand what exactly I am doing and would greatly appreciate any help.
My code works ok so far until I get to double digits. I guess I don't understand how to add ASCII '8' to '13'; using AAA which only works in register AL. Here is my code...I know it's a mess. Thanks in advance-vin

   .MODEL SMALL
   .STACK 64

   .DATA
FIBCODE   DB   '0','1', 19 dup ('$')
;_________________________________

   .CODE
MAIN:   MOV   AX,@DATA
   MOV   DS,AX
   CALL   FIBSEQ
   ;CALL   CONVERT
   ;CALL   DISPLAY
   MOV   AH,4CH
   INT    21H
;_______________________________
;THIS SUBROUTINE CREATES A FIBONACCI SEQUENCE
FIBSEQ   PROC
   MOV   CX,5
   CLC
   LEA   DI,FIBCODE
   LEA   SI,FIBCODE+1
   MOV   AX,0
BACK:   MOV   AL,[DI]
   ADC   AL,[SI]
   AAA
   OR   AL,30H
   MOV   [DI]+2,AL
   INC   DI
   INC    SI
   LOOP    BACK
   MOV   CX,5
   MOV   AL,[DI]
   ADD   AL,[SI]
   AAA
   OR   AX,3030H
   XCHG   AH,AL
   ;PUSH   CX
   ;MOV   CL,4
   ;SHL   AL,CL
   ;OR   AL,AH
   ;POP   CX
   MOV   [DI]+2,AX
   INC   DI
   INC   SI
   MOV   AL,[DI]
   ADC   AX,WORD PTR[SI]
   AAA
   OR   AX,3030H
   XCHG   AH,AL
   MOV   [DI]+2,AX
   RET
FIBSEQ   ENDP
   END   MAIN

raymond

The following tutorial may help you understand how to (and not to) use BCDs if you have not seen it yet. Although the examples were written for 32-bit assembly, you should be able to adapt them for your 16-bit coding.

http://www.ray.masmcode.com/BCDtut.html

After you have studied that tutorial, simply ask if something is not clear enough.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com