Starting from:
$30

$24

TWO problems -- Laboratory 2-Solved

There are TWO problems to this lab assignment.

Problem 1

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



Problem 2

The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45.

    • Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30.
    • Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15.
    • Divide 30 by 15, and get the result 2 with remainder 0, so 30=2·15+0.
    • The greatest common divisor of 210 and 45 is 15.

Formal description of the Euclidean algorithm

    • Input Two positive integers, a and b.
    • Output The greatest common divisor, g, of a and b.
    • Internal computation
        1. If a<b, exchange a and b.
        2. Divide a by b and get the remainder, r. If r=0, report b as the GCD of a and b.
        3. Replace a by b and replace b by r. Return to the previous step.


Your assignment is to write an assembler code (gcd.s) that asks the user two positive numbers and calculates their greatest common denominator.

For example, you program should produce the following outputs:

Enter first positive integer: 6

Enter second positive integer: 8

The GCD is 2

More products