Answer to Question #285103 in Assembler for Ahmed Ali

Question #285103

1) Write a program in assembly language using emu8086 to create the following Fibonacci series.


{0,1, 1, 2, 3, 5, 8}


The program must be compatible with emu8086.


1
Expert's answer
2022-01-06T08:52:03-0500

DATA SEGMENT

number      db 7

DATA ENDS

dw

code segment

start:

; set segment registers:

   mov ax, data

   mov ds, ax

    MOV ES,AX   


   mov    al, '0'      ; write first Fib = 0

   mov    ah, 0eh

   int    10h    


   mov    al, ' '

   mov    ah, 0eh

   int    10h  


   mov    al, '1'      ; write second Fib = 1

   mov    ah, 0eh

   int    10h  


   mov    al, ' '

   mov    ah, 0eh

   int    10h 


     mov   bl, 1

   cmp   number, 1            ; counter = 1?

   jz   return


   mov   al, 0      ; first = 0

   mov bl, 1      ; second = 1

   mov   cl, 2      ; counter

begin:   

   cmp   cl,number   ; counter = number?

   jz   return

   mov   dl, al      ; F(n-2)

   add   dl, bl      ; F(n) = F(n-1)+F(n-2) next = first + second

    mov   al, bl      ; first = second


     mov   bl, dl      ; second = next

   push ax

   mov   al, dl


   add    al, '0'

   mov    ah, 0eh

   int    10h


   mov    al, ' '

   mov    ah, 0eh

   int    10h  


   inc   cl                  ; counter++

   pop ax


   jmp begin

return:


   MOV AH,1         ; Waiting for a key press

   INT 16H


   mov ah, 4ch

   int 21h


CODE ENDS

END START



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS