Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Assembly Language write the following program. Problem Definition: Write a

ID: 3783042 • Letter: U

Question

Using Assembly Language write the following program.

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.
7) The usual requirements regarding documentation, readability, user-friendliness, etc., apply.

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.

Explanation / Answer

.data
programmerName               BYTE   "PROGRAMMER NAME", 0
programTitle       BYTE   "PRINT FIBONACCI NUMBERS WITHIN RANGE", 0
prompt_1           BYTE   "WHAT IS YOUR NAME? ", 0
prompt_2           BYTE   "Enter the number of Fibonacci terms you want to display between [1 - 46]", 0
num_fibo               DWORD   ?
previous1               DWORD   ?
previous2               DWORD   ?
spaces               BYTE   " ",0
goodbye               BYTE   "Goodbye, ", 0
first2           BYTE   "1 1 ", 0
first1           BYTE   "1", 0
temp               DWORD   ?
moduloFive           DWORD   5
UPPERLIMIT = 46
LOWERLIMIT = 1

;user's name
buffer               BYTE 21 DUP(0)
byteCount           DWORD   ?

;greet the user
hi                   BYTE   "Hi, ",0

;validate
highError           BYTE   "The number you entered is too high! Please enter number below 46", 0
lowError           BYTE   "The number you entered is too low! Please eneter number above 1", 0

;EC -> Setting Background Color and Text Color
val1 DWORD 11
val2 DWORD 16

.code
main PROC
   ; setting 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 programmerName
       call   WriteString
       call   CrLf

       ; EC Prompt
       mov       edx, OFFSET ec_prompt
       call   WriteString
       call   CrLf


       mov       edx, OFFSET prompt_1
       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
       call   WriteString
       call   CrLf

       ;userInstructions
topPrompt:
           mov       edx, OFFSET prompt_2
           call   WriteString
           call   CrLf

   ;getUserData
       call   ReadInt
       mov       num_fibo, eax

   ; Validate user data
       cmp       eax, UPPERLIMIT
       jg       TooHigh
       cmp       eax, LOWERLIMIT
       jl       TooLow
       je       JustOne
       cmp       eax, 2
       je       JustTwo

   ; displayFibs
       mov       ecx, num_fibo
       sub       ecx, 3           ; we start at iteration 3, the first two are taken care of by JustOne and JustTwo
       mov       eax, 1
       call   WriteDec
       mov       edx, OFFSET spaces
       call   WriteString
       call   WriteDec
       mov       edx, OFFSET spaces
       call   WriteString
       mov       previous2, eax
       mov       eax, 2
       call   WriteDec
       mov       edx, OFFSET spaces
       call   WriteString
       mov       previous1, eax

       fib:
           add       eax, previous2
           call   WriteDec
           mov       edx, OFFSET spaces
           call   WriteString
           mov       temp, eax
           mov       eax, previous1
           mov       previous2, eax
           mov       eax, temp
           mov       previous1, eax
           mov       edx, ecx
           cdq
           div       moduloFive
           cmp       edx, 0
           jne       skip
           call   CrLf
       skip:
               mov       eax, temp
               loop   fib
               jmp       TheEnd
TooHigh:
           mov       edx, OFFSET highError
           call   WriteString
           jmp       TopPrompt

TooLow:
           mov       edx, OFFSET lowError
           call   WriteString
           jmp       TopPrompt
JustOne:
           mov       edx, OFFSET first1
           call   WriteString
           jmp       TheEnd

JustTwo:
           mov       edx, OFFSET first2
           call   WriteString
           jmp       TheEnd
;farewell
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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote