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
Ulleksa [173]
3 years ago
10

Write a MASM program to calculate Fibonacci numbers:

Computers and Technology
1 answer:
IceJOKER [234]3 years ago
3 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
If you know the unit prices of two diffferent brands of an item,you are better able to
pantera1 [17]

Answer:

Compare the prices of the two brands.

Explanation:

Price can be defined as the amount of money that is required to be paid by a buyer (customer) to a seller (producer) in order to acquire goods and services.

In sales and marketing, pricing of products is considered to be an essential element of a business firm's marketing mix because place, promotion and product largely depends on it.

One of the importance associated with the pricing of products is that, it improves the image of a business firm.

Hence, if you know the unit prices of two different brands of an item, you are better able to compare the prices of the two brands. Subsequently, the buyer would be able to easily make a decision on which brand's product to purchase.

3 0
3 years ago
What are table buffers?
laiz [17]

Answer:

Table buffers are tools used to avoid the process of accessing a database in servers.

4 0
3 years ago
How do i add an answer on brainly i click to add an answer and it sends me to the home page
cricket20 [7]

Answer:  try to just add as little as possible then add the answser or just reload your browser

Explanation:

7 0
3 years ago
ILL GIVE BRAINLIEST. Read about one many types of computer languages that are available for computer coders. Use the website lis
jek_recluse [69]

Python is a programming language created by Guido van Rossum. This programming language has an implementation in C and one of the most important facts about it is that it's easy to learn for beginners and is a very versatile tool.

It can be used for almost anything and it's easy to set up and run using the large number of libraries avaliable.

Some uses for Python are in :

- Machine Learning and AI

- Research and data interpretation

- BackEnd Server

- Simulations

- Games (?)

- Bots

- Simple automatization tasks.

Based on the large number of applications and the simplicity I think Python is one of the most valuable languages to learn.

7 0
3 years ago
Jack is using a document that has multiple references to his company as Company ABC, LLC. He would like to change these values t
Alinara [238K]

Copy the text you want to use as a replacement and use the Find dialog box to find each value to paste the replacement text.

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • 1. Which markup language adds the ability to use video without requiring the user to download add-ons?
    13·1 answer
  • The merge process involves which two types of files?
    5·1 answer
  • Discuss two things you’ve learned about computers
    6·1 answer
  • Which is an example of line-of-sight Internet service?<br> Cable<br> DSL<br> Fiber<br> WiMax
    7·1 answer
  • Your help will help me understand my answers by comparing to yours. Your kind contribution is very much appreciated.
    6·1 answer
  • Someone asks you for help with a computer that hangs at odd times. You turn it on and work for about 15 minutes, and then the co
    10·1 answer
  • given:an int variable k,an int array currentMembers that has been declared and initialized,an int variable memberID that has bee
    5·1 answer
  • Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd. Ex: If the input is: 2
    13·1 answer
  • Discuss how the Internet has made our communication hypertextual, omnidirectional, and more interactive
    6·1 answer
  • What is number system?<br>​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!