fork download
  1. TITLE Fibonacci Numbers (Project02.asm)
  2.  
  3. ; Author: Andrew Pierno
  4. ; Description: Write a program to calculate Fibonacci numbers.
  5. ; • Display the program title and programmer’s name. Then get the user’s name, and greet the user.
  6. ; • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer
  7. ; in the range [1 .. 46].
  8. ; • Get and validate the user input (n).
  9. ; • Calculate and display all of the Fibonacci numbers up to and including the nth term. The results should be
  10. ; displayed 5 terms per line with at least 5 spaces between terms.
  11. ; • Display a parting message that includes the user’s name, and terminate the program.
  12.  
  13. INCLUDE Irvine32.inc
  14.  
  15. .data
  16. myName BYTE "Andrew Pierno ", 0
  17. programTitle BYTE "Fibonacci Numbers by ", 0
  18. instructions BYTE "Please enter two numbers, and I'll show you the sum, difference, product, quotient, and remainder.", 0
  19. prompt_1 BYTE "What is your name? ", 0
  20. prompt_2 BYTE "Enter the number of Fibonacci terms you would like to see. Please enter a number between [1 - 46]", 0
  21. ec_prompt BYTE "EC: Doing something awesome: Setting text color to teal-ish", 0
  22. numFib DWORD ?
  23. prev1 DWORD ?
  24. prev2 DWORD ?
  25. spaces BYTE " ",0
  26. goodbye BYTE "Goodbye, ", 0
  27. firstTwo BYTE "1 1 ", 0
  28. firstOne BYTE "1", 0
  29. temp DWORD ?
  30. moduloFive DWORD 5
  31. UPPERLIMIT = 46
  32. LOWERLIMIT = 1
  33.  
  34. ;user's name
  35. buffer BYTE 21 DUP(0)
  36. byteCount DWORD ?
  37.  
  38. ;greet user
  39. hi BYTE "Hi, ",0
  40.  
  41. ;validation
  42. tooHighError BYTE "The number you entered is too high! It must be 46 or below. ", 0
  43. tooLowError BYTE "The number you entered is too low! It must be 1 or above. ", 0
  44.  
  45. ;EC -> Doing something awesome: Setting Background Color and Text Color
  46. val1 DWORD 11
  47. val2 DWORD 16
  48.  
  49. .code
  50. main PROC
  51.  
  52. ;EC: doing something awesome like setting the text color
  53.  
  54. ; set text color to teal
  55. mov eax, val2
  56. imul eax, 16
  57. add eax, val1
  58. call setTextColor
  59.  
  60. ; INTRODUCTION
  61. mov edx, OFFSET programTitle
  62. call WriteString
  63. mov edx, OFFSET myName
  64. call WriteString
  65. call CrLf
  66.  
  67. ; EC Prompt
  68. mov edx, OFFSET ec_prompt
  69. call WriteString
  70. call CrLf
  71.  
  72.  
  73. mov edx, OFFSET prompt_1
  74. call WriteString
  75. call CrLf
  76.  
  77.  
  78. ; get user's name
  79. mov edx, OFFSET buffer ;point to the buffer
  80. mov ecx, SIZEOF buffer ; specify max characters
  81. call ReadString
  82. mov byteCount, eax
  83.  
  84. ; greet the user
  85. mov edx, OFFSET hi
  86. call WriteString
  87. mov edx, OFFSET buffer
  88. call WriteString
  89. call CrLf
  90.  
  91. ; USER INSTRUCTIONS
  92. topPrompt:
  93. mov edx, OFFSET prompt_2
  94. call WriteString
  95. call CrLf
  96.  
  97. ; GET USER DATA
  98. call ReadInt
  99. mov numFib, eax
  100.  
  101. ; Validate user data
  102. cmp eax, UPPERLIMIT
  103. jg TooHigh
  104. cmp eax, LOWERLIMIT
  105. jl TooLow
  106. je JustOne
  107. cmp eax, 2
  108. je JustTwo
  109.  
  110. ; DISPLAY FIBS
  111.  
  112. ; prepare loop (post-test), do the first two manually
  113.  
  114. mov ecx, numFib
  115. sub ecx, 3 ; we start at iteration 3, the first two are taken care of by JustOne and JustTwo
  116. mov eax, 1
  117. call WriteDec
  118. mov edx, OFFSET spaces
  119. call WriteString
  120. call WriteDec
  121. mov edx, OFFSET spaces
  122. call WriteString
  123. mov prev2, eax
  124. mov eax, 2
  125. call WriteDec
  126. mov edx, OFFSET spaces
  127. call WriteString
  128. mov prev1, eax
  129.  
  130. fib:
  131. ; add prev 2 to eax
  132. add eax, prev2
  133. call WriteDec
  134.  
  135. mov edx, OFFSET spaces
  136. call WriteString
  137.  
  138. mov temp, eax
  139. mov eax, prev1
  140. mov prev2, eax
  141. mov eax, temp
  142. mov prev1, eax
  143.  
  144. ;for spacing (first time it should be % 3, rest %5)
  145. mov edx, ecx
  146. cdq
  147. div moduloFive
  148. cmp edx, 0
  149. jne skip
  150. call CrLf
  151.  
  152. skip:
  153. ; restore what was on eax
  154. mov eax, temp
  155. ; if ecx % 3 = 0 call CrLf
  156. loop fib
  157. jmp TheEnd
  158.  
  159. TooHigh:
  160. mov edx, OFFSET tooHighError
  161. call WriteString
  162. jmp TopPrompt
  163.  
  164. TooLow:
  165. mov edx, OFFSET tooLowError
  166. call WriteString
  167. jmp TopPrompt
  168. JustOne:
  169. mov edx, OFFSET firstOne
  170. call WriteString
  171. jmp TheEnd
  172.  
  173. JustTwo:
  174. mov edx, OFFSET firstTwo
  175. call WriteString
  176. jmp TheEnd
  177.  
  178. ; FAREWELL
  179. TheEnd:
  180. call CrLf
  181. mov edx, OFFSET goodbye
  182. call WriteString
  183. mov edx, OFFSET buffer
  184. call WriteString
  185. call CrLf
  186.  
  187. exit ; exit to operating system
  188. main ENDP
  189.  
  190. END main
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.asm:1: error: parser: instruction expected
prog.asm:13: error: parser: instruction expected
prog.asm:16: error: parser: instruction expected
prog.asm:17: error: parser: instruction expected
prog.asm:18: error: parser: instruction expected
prog.asm:19: error: parser: instruction expected
prog.asm:20: error: parser: instruction expected
prog.asm:21: error: parser: instruction expected
prog.asm:22: error: parser: instruction expected
prog.asm:23: error: parser: instruction expected
prog.asm:24: error: parser: instruction expected
prog.asm:25: error: parser: instruction expected
prog.asm:26: error: parser: instruction expected
prog.asm:27: error: parser: instruction expected
prog.asm:28: error: parser: instruction expected
prog.asm:29: error: parser: instruction expected
prog.asm:30: error: parser: instruction expected
prog.asm:31: error: parser: instruction expected
prog.asm:32: error: parser: instruction expected
prog.asm:35: error: parser: instruction expected
prog.asm:36: error: parser: instruction expected
prog.asm:39: error: parser: instruction expected
prog.asm:42: error: parser: instruction expected
prog.asm:43: error: parser: instruction expected
prog.asm:46: error: parser: instruction expected
prog.asm:47: error: parser: instruction expected
prog.asm:50: error: parser: instruction expected
prog.asm:61: error: comma, colon, decorator or end of line expected after operand
prog.asm:63: error: comma, colon, decorator or end of line expected after operand
prog.asm:68: error: comma, colon, decorator or end of line expected after operand
prog.asm:73: error: comma, colon, decorator or end of line expected after operand
prog.asm:79: error: comma, colon, decorator or end of line expected after operand
prog.asm:80: error: comma, colon, decorator or end of line expected after operand
prog.asm:85: error: comma, colon, decorator or end of line expected after operand
prog.asm:87: error: comma, colon, decorator or end of line expected after operand
prog.asm:93: error: comma, colon, decorator or end of line expected after operand
prog.asm:118: error: comma, colon, decorator or end of line expected after operand
prog.asm:121: error: comma, colon, decorator or end of line expected after operand
prog.asm:126: error: comma, colon, decorator or end of line expected after operand
prog.asm:135: error: comma, colon, decorator or end of line expected after operand
prog.asm:160: error: comma, colon, decorator or end of line expected after operand
prog.asm:165: error: comma, colon, decorator or end of line expected after operand
prog.asm:169: error: comma, colon, decorator or end of line expected after operand
prog.asm:174: error: comma, colon, decorator or end of line expected after operand
prog.asm:181: error: comma, colon, decorator or end of line expected after operand
prog.asm:183: error: comma, colon, decorator or end of line expected after operand
prog.asm:188: error: symbol `main' redefined
prog.asm:188: error: parser: instruction expected
prog.asm:190: error: parser: instruction expected
ld: cannot find prog.o: No such file or directory
stdout
Standard output is empty