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
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 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...
(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...
This program is for kindergartners to practice knowledge on numbers divisible by 5. Write a code...
This program is for kindergartners to practice knowledge on numbers divisible by 5. Write a code using a while loop, which keeps asking the user to enter an number divisible by 5. The program(i.e the while loop) terminates when the user enters a number divisible by 5, but keeps running if the user fails to enter a number divisible by 5. Also print appropriate message after each failed try. When successful, tell the user how many attempts were needed for...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Find the error in the following psuedocode // This program asks the user to enter a...
Find the error in the following psuedocode // This program asks the user to enter a number between 1 and 5 and validates the input. Declare Integer number // Get a number from the user. Display "Enter a number between 1 and 5." Input number // Make sure the number is between 1 and 5. While number < 1 AND number > 5 Display "ERROR: The number must be between 1 and 5. " Display "Enter a number between 1...
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT