
Respuesta :
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