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]
2 years ago
10

Write a MASM program to calculate Fibonacci numbers:

Computers and Technology
1 answer:
IceJOKER [234]2 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
Match the characteristics to the mobile operating system that it describes.
uranmaximum [27]
I think it’s Apple ios
It’s definitely not Microsoft but my guess is Apple
3 0
3 years ago
Which character is used to begin a comment?
Aloiza [94]
# is used to begin a comment.
8 0
3 years ago
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program where the
SCORPION-xisa [38]

a aj ji hfjizbhig jiad jv hD jug vhi SDhvb hbnsdubghi

a biabihb hsjgbidbihdgbhibsrhkgbhibshibvghibsdgjo

asbihdg hibsihbghibdshibghbshbg9bhisdbghivbhbhir

aa sbuogjanjfjnbsujoenngobuewwwwwwwwwwwwwwwwwwwwwwww0o

8 0
2 years ago
Which girl is he baddest 1. Shawty 2.Lisa 3.Ashley
Ainat [17]

Answer:

. . . . . . . S H A W T Y.. . .. . .

3 0
2 years ago
What is the value of count after this nested FOR loop executes fully.
Alisiya [41]

Answer:

168 (although the =< must be corrected to <=)

Explanation:

int count = 0;

for (int row = 4; row <= 15; row++)

for (int col = 0; col < 13; col = col +2)

count+=2;

The inner for loop runs 7 times (for col = 0,2,4,6,8,10,12). Anything higher is not less than 13. Therefore the inner loop increments count by 2 seven times, i.e. it increments count by 14.

The outer for loop runs 12 times (for row = 4,5,6,7,8,9,10,11,12,13,14,15).

If the count is incremented by 14 twelve times, you are incrementing it by 14*12 = 168.

Therefore the count goes from 0 to 168 after the nested loops.

5 0
3 years ago
Other questions:
  • In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the mont
    14·1 answer
  • Suppose you send data to the 11111111 11111111 11111111 11111111 ip address on an ipv4 network. to which device(s) are you trans
    15·1 answer
  • Find a, b, and c<br> A a=4 square root of 6 b= 8 square root of 2 ; c= 4 square root of 2
    12·1 answer
  • Why is the ipad not considered to be an enterprise-worthy device
    8·1 answer
  • WILL DO A BRIANLY! Use an algorithm to help the Python Turtle get to the finish line in 10 steps by using only the 3 commands be
    12·1 answer
  • Explain the importance of mobile computing in communication​
    7·2 answers
  • Bill, a project manager, wants to hire external resources. What step should Bill take before hiring external resources?
    7·1 answer
  • The cost to ship a package is a flat fee of 75 cents plus 25 cents per pound. 1. Declare a const named CENTS_PER_POUND and initi
    12·1 answer
  • Widow in respect to word processing ​
    15·1 answer
  • Which of the following tasks are suitable for creating an algorithm? Choose all that apply
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!