1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mafiozo [28]
3 years ago
12

Description: Write a MASM program to calculate Fibonacci numbers: 1. Display the program title and your name. Then get the user’

s name and greet the user. 2. Prompt the user to enter the number of Fibonacci terms to be displayed. Advice the user to enter an integer in the range [1 – 46]. 3. Get and validate the user input. 4. 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. 5. Display a goodbye message that includes the user’s name and terminates the program.
Engineering
1 answer:
Marta_Voda [28]3 years ago
6 0

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

You might be interested in
the coil polarity in a waste spark system is determined by the direction in which the coil is wound (left hand rule for conventi
zaharov [31]
The coil polarity in a waste-spark system is determined by the direction in which the coil is wound (left-hand rule for conventional current flow)and can’t be changed. For example, if a V-8 engine has a firing order of 18436572 and the number 1 cylinder is on compression, which cylinder will be on the exhaust stroke?
3 0
3 years ago
A tool chest has 950 N weight that acts through the midpoint of the chest. The chest is supported by feet at A and rollers at B.
Mazyrski [523]

Answer:

P > 142.5 N  (→)

the motion sliding

Explanation:

Given

W = 959 N

μs = 0.3

If we apply

∑ Fy = 0 (+↑)

Ay + By = W

If  Ay = By

2*By = W

By = W / 2

By = 950 N / 2

By = 475 N (↑)

Then  we can get F (the force of friction) as follows

F = μs*N = μs*By

F = 0.3*475 N

F = 142.5 N (←)

we can apply

P - F  > 0

P  > 142.5 N (→)

the motion sliding

6 0
3 years ago
For which of the following structures would a pile foundation be appropriate? (Select all that apply.)
tiny-mole [99]

Answer:

Football stadium on rocky soil

Skyscraper on bedrock

Apartment building on sandy soil

Explanation:

6 0
3 years ago
Which of the following is true about ideal standards? a.Ideal standards provide allowance for normal breakdowns and interruption
marysya [2.9K]

Answer: D. All of the choice A, B and C are correct.

8 0
4 years ago
Assign deliveryCost with the cost (in dollars) to deliver a piece of baggage weighing baggageWeight. The baggage delivery servic
Sholpan [36]

Answer: y = x * 1dollars - 30dollars

Explanation:

Giving that the delivery cost in dollar is potent for all x > = 50 pounds of wght

Y = (x - 50)*1 dollar + c ...equ 1

Y = delivery cost equation in dollars

x = weigt of baggage for delivery

c = 20dollars = down payment for the first 50 pound weight of baggage

Equ 1 becomes

Y = (x)dollars - 50 dollars + 20 dollars

Y = (x) dollars -30 dollars

4 0
4 years ago
Other questions:
  • A bar of 75 mm diameter is reduced to 73mm by a cutting tool while cutting orthogonally. If the mean length of the cut chip is 7
    10·1 answer
  • What does WCS stand for? A. Western CAD System B. Worldwide Coordinate Sectors C. World Coordinate System D. Wrong CAD Settings
    10·1 answer
  • Intravenous infusions are usually driven by gravity by hanging the bottle at a sufficient height to counteract the blood pressur
    11·1 answer
  • 10. Which of these requires a wheel alignment after replacement?
    11·2 answers
  • white Sands national monument is a large area made of white sand dunes. what is likely to be true of this area?​
    8·1 answer
  • A 3.52 kg steel ball is tossed upward from a height of 6.93 meters above the floor with a vertical velocity of 2.99 m/s. What is
    14·1 answer
  • The three suspender bars AB, CD, and EF are made of A-36 steel and have equal cross-sectional areas of 500 mm2. Determine the av
    9·1 answer
  • QUESTION:
    13·1 answer
  • What energy does a curcuit board run on
    11·2 answers
  • What are the most used electronic tools for electronic works?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!