Question

In: Computer Science

In Assembly Code write an assembler code (Fibonacci.s) and show results The Fibonacci Sequence is a...

In Assembly Code

write an assembler code (Fibonacci.s) and show results

The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers.

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc.

The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not 5.

Your assignment is to write an assembler code (Fibonacci.s) that asks the user for the nth term in the Fibonacci sequence. Your program should then calculate the nth Fibonacci number and print it out.

For example, you program should produce the following outputs:

Enter Fibonacci term: 6

The 6th Fibonacci number is 8

Solutions

Expert Solution

.MODEL SMALL

.STACK 64

.DATA
        VAL1    DB      01H
        VAL2    DB      01H
        LP      DB      00H
        V1      DB      00H
        V2      DB      00H
        NL      DB      0DH,0AH,'$'

.CODE

MAIN PROC
        MOV AX,@DATA
        MOV DS,AX

        MOV AH,01H
        INT 21H
        MOV CL,AL
        SUB CL,30H
        SUB CL,2

        MOV AH,02H
        MOV DL,VAL1
        ADD DL,30H
        INT 21H

        MOV AH,09H
        LEA DX,NL
        INT 21H

        MOV AH,02H
        MOV DL,VAL2
        ADD DL,30H
        INT 21H

        MOV AH,09H
        LEA DX,NL
        INT 21H


DISP:
        MOV BL,VAL1
        ADD BL,VAL2

        MOV AH,00H
        MOV AL,BL
        MOV LP,CL
        MOV CL,10
        DIV CL
        MOV CL,LP

        MOV V1,AL
        MOV V2,AH

        MOV DL,V1
        ADD DL,30H
        MOV AH,02H
        INT 21H

        MOV DL,V2
        ADD DL,30H
        MOV AH,02H
        INT 21H

        MOV DL,VAL2
        MOV VAL1,DL
        MOV VAL2,BL

        MOV AH,09H
        LEA DX,NL
        INT 21H


        LOOP DISP

        MOV AH,4CH
        INT 21H

MAIN ENDP
END MAIN

Related Solutions

( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence...
( Assembly Language ) Write a program that computes the 7th fibonacci number. The fibonacci sequence - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … what is the initialization of a, b, and d? - a b d 1 ? ? 1 2 ? ? 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8 7 5 8 13 wrong initialization - a b d 1 0 1 1 2...
3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y,...
3 – Write the following sequence of code into the RISC-V assembler. Assume that x, y, and z are stored in registers x18, x19, and x20 respectively. z = x - 2; x = z +4 - y;
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
What is the proper way to define an assembly code in in-line assembler x86 for this...
What is the proper way to define an assembly code in in-line assembler x86 for this case: multiplication without using mul/imul, using hexadecimal numbers for "shl" instruction.
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence,...
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0,...
Write a R-script to (and show the outputs of your code) (a) Create a sequence of...
Write a R-script to (and show the outputs of your code) (a) Create a sequence of numbers starting at 3.5 and ending at 10.7 with increments of 0.79. Find the variance and mean of those numbers. And finally sort the vector in a decreasing manner (b) Create a 3 different 3 by 3 matrices such that each of the numbers 1,2,...,9 appear exactly once (Sudoku style) in each of the matrices.
Write a recursive and an iterative function to calculate the nth element in a Fibonacci sequence....
Write a recursive and an iterative function to calculate the nth element in a Fibonacci sequence. A Fibonacci sequence is defined as the element 1, followed by another 1, and each element thereafter is the sum of the previous two elements. For example, the first 9 elements of a Fibonacci sequence are: 1 2 3 5 8 13 21 34 This famous sequence was originally used to predict the growth of rabbit populations! Once you have each of the functions...
A Fibonacci sequence, is a sequence of numbers with the property that each number is the...
A Fibonacci sequence, is a sequence of numbers with the property that each number is the sum of the two preceding Fibonacci numbers, starting from 0 and 1. Fibonacci number are usually denoted by Fn, where Fn is the nth Fibonacci number. Thus Fn = 0, and Fn = 1, and Fn = Fn-1 + Fn-2, n ≥ 2. Here are the first few Fibonacci numbers: F0=0 (by definition) F1=1 (by definition) F2 = F1 + F0 = 1 +...
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
how to find arithmetic sequence, geometric sequence, and fibonacci sequence on excel?
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT