Question

Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...

Written in MASM Assembly

Problem Definition:
Write a program to calculate Fibonacci numbers.
• Display the program title and programmer’s name. Then get the user’s name, and greet the user.
• Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46].
• Get and validate the user input (n).
• Calculate and display all of the Fibonacci numbers up to and including the nth term. The results should be displayed 5 terms per line with at least 5 spaces between terms.
• Display a parting message that includes the user’s name, and terminate the program.
Requirements:
1) The programmer’s name and the user’s name must appear in the output.
2) The loop that implements data validation must be implemented as a post-test loop.
3) The loop that calculates the Fibonacci terms must be implemented using the MASM loop instruction.
4) The main procedure must be modularized into at least the following sections (procedures are not required this time):
a. introduction
b. userInstructions
c. getUserData
d. displayFibs
e. farewell
5) Recursive solutions are not acceptable for this assignment. This one is about iteration.
6) The upper limit should be defined and used as a constant.

Notes:
1) It is not necessary to store the Fibonacci numbers in an array. The terms may be displayed as they are generated.
2) The second-order Fibonacci sequence is defined as:
a. The first two terms are both 1.
b. All other terms are calculated as the sum of the two previous terms.
c. The reason for restricting n to [1 .. 46] is that the 47th Fibonacci number is too big for DWORD data type.

Example:

Fibonacci Numbers
Programmed by Leonardo Pisano
What’s your name? Paul
Hello, Paul
Enter the number of Fibonacci terms to be displayed
Give the number as an integer in the range [1 .. 46].
How many Fibonacci terms do you want? 50
Out of range. Enter a number in [1 .. 46]
How many Fibonacci terms do you want? 14
1 1 2 3 5
8 13 21 34 55
89 144 233 377
Results certified by Leonardo Pisano.
Goodbye, Paul.

Homework Answers

Answer #1

INCLUDE Irvine32.inc

.data

myName                         BYTE    " LEONARDO PISANO " , 0

programTitle                    BYTE     " Fibonacci Numbers by " , 0

instructions                     BYTE    " Please enter two numbers and I'll show you the sum , difference , product ,

                                                      quotient and remainder . " , 0

prompt_1                                       BYTE   " What is your name ? " , 0

prompt_2                                       BYTE   " Enter the number of Fibonacci terms you would like to see . Please

                                                                   enter a number between [1-46] " , 0

ec_prompt                                    BYTE    " EC : Doing something awesome : Setting test color to teal-ish " , 0

numFib                                        DWORD     ?

prev1                                           DWORD     ?

prev2                                           DWORD     ?

spaces                                        BYTE        "         " , 0

goodbye                                                       BYTE " Goodbye , " , 0

firstTwo                                        BYTE       " 1          1     " , 0

forstOne                                      BYTE       " 1 " , 0

temp                                           DWORD      ?

moduloFive                                  DWORD      5

UPPERLIMIT = 46

- LOWERLIMIT = 1

+ LOWERLIMIT = 1

; user's name

buffer                                             BYTE   21   DUP( 0 )

byteCount                                      DWORD      ?

;greet user

hi                                                                     BYTE " Hi , " , 0

; validation

tooHighError          BYTE     " The number you entered is too high ! It must be 46 or below . " , 0

tooLowError                       BYTE " The number you entered is too low ! It must be 1 or above . " , 0

; EC -> Doing something awesome : Setting Background Color and Text Color

val1    DWORD 11

val2    DWORD 16

.code

main PROC

       ; EC : Doing something awesome like setting the text color

       ; set text color to teal

                mov eax , val2

                imul eax , 16

                add eax , val1

                call setTextColor

          ; INTRODUCTION

                mov             edx , OFFSET programTitle

                call       WriteString

                mov             edx , OFFSET myName

                call      WriteString

                call      CrLf

                ; EC Prompt

                mov                edx , OFFSET ec_prompt

                call       WriteString

                call        CrLf

                ; get user's name

                 mov             edx , OFFSET buffer       ;   point to the buffer

                 mov               ecx , SIZEOF       buffer   ; specify max characters

                 call        ReadString

                 mov       byteCount , eax

                 ; greet the user

                 mov                     edx , OFFSET hi

                 call      WriteString

                 mov                      edx , OFFSET buffer

                 mov      WriteString

                  call      CrLf

                 ; GET USER DATA

                           call    ReadInt

                           mov               numFib , eax

                      ; validate user data

                           cmp               eax , UPPERLIMIT
                             jg                 TooHigh

                           cmp               eax , LOWERLIMIT

                             jl                  TooLow

                             je                 JustOne

                            cmp             eax , 2

                             je                 JustTwo

                   ; DISPLAY FIBS

                             ; prepare loop ( post- test ) , do the first two manually

                                   mov         ecx , numFib

                                   sub          ecx , 3

                                    mov         eax , 1

                                   call        WriteDec

                                   mov              edx , OFFSET   spaces

                                   call       WriteString

                                  call        WriteDec     

                                  mov              edx , OFFSET spaces

                                   call      WriteString

                                 mov               prev 2 , eax

                                 mov               eax 2 , 2

                                  call   WriteDec

                                  mov              edx , OFFSET spaces

                                  call     WriteString

                                 mov               prev 1 , eax

                                 fib :

                                            ; add prev 2 to eax

                                               add            eax , prev 2

                                               call      WriteDec

                                               mov            edx , OFFSET spaces

                                               call       WriteString

                                              mov             temp , eax

                                              mov             eax , prev1

                                              mov             prev2 , eax

                                               mov            eax , temp

                                              mov             prev1 , eax

                                            ; for spacing ( first time it should be % 3 , rest % 5 )

                                            mov    edx , cdx

                                            cdq

                                            div      moduloFive

                                            cmp    edx , 0

                                           jne      skip

                                          call      CrLf

                             skip :

                                        ;restore what was on eax

                                         mov        eax , temp

                                        ; if ecx % 3 = 0 call CrLf

                                         loop fib

                   jmp                 TheEnd

- TooHigh :

+ TooHigh :

                      mov          edx , OFFSET tooHighError

                      call   WriteString

                      jmp          TopPrompt

                     jmp            TopPrompt

JustOne

                         mov      edx , OFFSET firstOne

                         call WriteString

                         jmp      TheEnd

                         jmp       TheEnd

JustTwo :

                          mov   edx , OFFSET firstTwo

                          call WriteString

-                        jmp        TheEnd

+                      jmp TheEnd

           ; FAREWELL

- TheEnd

+ TheEnd

                             call     CrLf

                             mov       edx , OFFSET goodbye

                             call     WriteString

                             mov               edx , OFFSET   buffer

                             call     WriteString

                             call     CrLf

        exit    ; exit to operating system

    main ENDP

- END main

+ END main

                

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store...
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store the numbers in an array. The c++ program asks the user for an input to enter a positive integer 'n' and display the nth fibonacci number "FibN" that is stored inside of the array
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
Please Write the whole program in assembly i am able to calculate the fibonacci series but...
Please Write the whole program in assembly i am able to calculate the fibonacci series but not sure how to print it in reverse order. Please give a Complete code !! Programming Exercise 1 (10 points): [call it Ass2-Q1.asm] Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by: Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1) Thus, if the input is N...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The sequence Fn of Fibonacci numbers is defined by the recurrence relation: Fn = Fn-1 + Fn with seed values F1 = 1 F2 = 1 For more information on...
Write a C program Design a program that uses an array to store 10 randomly generated...
Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is...
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is generated by adding the two most recent sequence numbers together, i.e., 1, 1, 1+1-2, 1+2=3, 2+3=5, 3+5=8, … The user will enter the number of terms in the sequence to be displayed. Assemble this program using the VSC assembler (ASM), and simulate this program using the VSC simulator (SIM). Include a copy of the source listing (SOURCE.DAT), the assembled listing (SLIST.DAT) and the simulation...
ARM Assembly Code The Fibonacci Sequence is a series of integers. The first two numbers in...
ARM Assembly Code 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...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
use python Write a program that uses a for loop to display all prime numbers within...
use python Write a program that uses a for loop to display all prime numbers within the range [500, 800] (hint: prime numbers are numbers that have only 2 factors: 1 and themselves. You can use a loop function to check if a number has a factor other than 1 or itself using % operation)
Write the following ANNA assembly language programs. 1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously...
Write the following ANNA assembly language programs. 1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously prompt the user for numbers. When the user enters a negative number, print the highest positive number entered by the user and exit the program. Print a zero if they did not enter any positive numbers. 2.DivisionWrite an ANNA assembly program (div.ac) that divides two positive numbers that come from user input and returns both the quotient and the remainder. For example, if the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT