fork(2) download
  1.  
  2. ; Author: Riam S. Kidd
  3. ; Due Date: 7/14/13
  4. ; Course: CS 271
  5. ; Program Description:
  6. ; Program 2:
  7. ; Write a program to calculate Fibonacci numbers.
  8. ; Display the program title and programmer’s name. Then get the user’s name, and greet the user.
  9. ; Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46].
  10. ; Get and validate the user input (n).
  11. ; Calculate and display all of the Fibonacci numbers up to and including the nth term.
  12. ; The results should be displayed 5 terms per line with at least 5 spaces between terms (I failed to do this and my comments are mentioned below)
  13. ; Display a parting message that includes the user’s name, and terminate the program.
  14. ; Tried extra credit: do something incredible. Made a greeting window, changed color of program title, and changed the color of the printout for better viewing for the user
  15.  
  16.  
  17.  
  18. ;defined constant for upper limit of Fibonacci terms
  19. FIBSTERM = 47
  20.  
  21. .data
  22.  
  23. caption db "Fibonacci Numbers", 0 ;Message Box (Do something incredible for me!)
  24. HelloMsg BYTE "Welcome to Fibonacci Number for Fun!", 0dh, 0ah
  25. BYTE "Click OK to Begin", 0
  26. title1 BYTE " Fibonacci Numbers", 0
  27. title2 BYTE " Programmed by Riam S. Kidd", 0
  28. rules1 BYTE "Enter the number of Fibonacci terms to be displayed", 0
  29. rules2 BYTE "Give the number as an integer in the range [1 .. 46].", 0
  30. askName BYTE "What's your name? ", 0
  31. userName BYTE 33 DUP(0) ;string to be entered by user
  32. greetUser BYTE "Nice to meet you, ", 0
  33. askFibnum BYTE "How many Fibonacci terms do you want? ", 0
  34. invalidNum BYTE "That's an invalid number. Please enter a number in the range of 1 and 46." ,0
  35. goodBye BYTE "Have a Nice Day! Good-Bye ", 0
  36. exclaim BYTE " ! ", 0
  37. fibsNum DWORD ? ;get number of Fib terms to display from user
  38. dNum DWORD ?
  39. remainNum DWORD ?
  40.  
  41. .code
  42. main PROC
  43.  
  44. ;Message Box Display
  45. mov ebx,OFFSET caption
  46. mov edx,OFFSET HelloMsg
  47. call MsgBox
  48.  
  49. ;Display title 1: Fibonacci Numbers
  50. mov eax, green + (black*16) ;sets text color to green
  51. call SetTextColor
  52. mov edx,OFFSET title1 ;set up for call to WriteString
  53. call WriteString
  54. call Crlf
  55. call Crlf
  56.  
  57. ;Display title 2: programmer's name
  58. mov eax, white + (black*16) ;sets text color back to white
  59. call SetTextColor
  60. mov edx,OFFSET title2
  61. call WriteString
  62. call Crlf
  63. call Crlf
  64.  
  65. ;Display instructions line 1
  66. mov edx,OFFSET rules1
  67. call WriteString
  68. call Crlf
  69.  
  70. ;Display instructions line 2
  71. mov edx,OFFSET rules2
  72. call WriteString
  73. call Crlf
  74. call Crlf
  75.  
  76. ;Get user name
  77. mov edx, OFFSET askName
  78. call WriteString
  79. mov edx, OFFSET userName
  80. mov ecx, 32
  81. call ReadString
  82.  
  83. ;Greet user by name
  84. mov edx, OFFSET greetUser
  85. call WriteString
  86. mov edx, OFFSET userName
  87. call WriteString
  88. call Crlf
  89.  
  90. ;get number of Fib terms to display from user
  91. input:
  92. mov edx,OFFSET askFibnum
  93. call WriteString
  94. call ReadInt
  95. mov fibsNum, eax
  96. call Crlf
  97.  
  98. ;validate user input
  99. decide:
  100. mov eax, fibsNum
  101. cmp eax, FIBSTERM ;check condition that input is not greater than 47
  102. jge greater ;out of bounds input
  103. jl initial ;go to intial if Fib terms are acceptable
  104.  
  105. greater:
  106. mov edx, OFFSET invalidNum ;displays message if user input is invalid and reminds user to enter correct number within range
  107. call WriteString
  108. call Crlf
  109. call Crlf
  110. jmp input ;prompts user to start again
  111. call Crlf
  112.  
  113. ;initializing Fibonacci sequence -- if this is not in place it doesn't calculate correctly
  114. initial:
  115. mov eax, white + (green*16); white on green background -- highlights Fibonacci printout
  116. call SetTextColor
  117. mov ebx, 1 ; initial setup
  118. mov edx, 0
  119. mov ecx, fibsNum ; get number of Fib
  120.  
  121. ;loop calculating and printing Fibonacci sequence
  122. L1:
  123. mov eax, ebx
  124. add eax, edx
  125. mov ebx, edx
  126. mov edx, eax
  127. call WriteDec ;print out Fibonacci numbers
  128. mov al, TAB ;horizontal tab
  129. call WriteChar ;write the tab displays it aligned
  130. loop L1 ;subtract 1 from ecx, if ecx !=0, goes to L1. reach 0 terminates loop
  131. mov eax, white + (green*16) ;white on green background
  132. call SetTextColor
  133.  
  134. ;Put code as comment because it won't make new line after 5 characters.
  135. ;I tried but failed to make it work.
  136. ;L2:
  137.  
  138. ;mov eax, 1 ;define counter variable has initial value of 1.
  139. ;cdq
  140. ;mov ebx, 5 ; divide by 5
  141. ;div ebx
  142. ;inc eax ; remainder incremented if != 0
  143. ;mov dNum, eax
  144. ;mov remainNum, edx
  145. ;cmp remainNum, 0 ;if remainer is not equal to 0 then counter is incremented
  146. ;cmp eax, fibsNum ;checks if ebx (counter is greater than fibsNum. If it is then loop terminates. If less then loops.
  147. ;jle L2
  148.  
  149. mov eax, white + (black*16) ; white on black background -- goes back to default color and background
  150. call SetTextColor
  151. call Crlf
  152. call Crlf
  153.  
  154. ;Farewell Message
  155. mov edx, OFFSET GoodBye
  156. call WriteString
  157. mov edx, OFFSET userName
  158. call WriteString
  159. mov edx, OFFSET exclaim
  160. call WriteString
  161. call Crlf
  162. call Crlf
  163.  
  164. exit ; exit to operating system
  165.  
  166. main ENDP
  167.  
  168. END main
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.asm:19: error: parser: instruction expected
prog.asm:24: error: parser: instruction expected
prog.asm:25: error: label or instruction expected at start of line
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:33: error: parser: instruction expected
prog.asm:34: error: parser: instruction expected
prog.asm:35: error: parser: instruction expected
prog.asm:36: error: parser: instruction expected
prog.asm:37: error: parser: instruction expected
prog.asm:38: error: parser: instruction expected
prog.asm:39: error: parser: instruction expected
prog.asm:42: error: parser: instruction expected
prog.asm:45: error: comma, colon, decorator or end of line expected after operand
prog.asm:46: error: comma, colon, decorator or end of line expected after operand
prog.asm:52: error: comma, colon, decorator or end of line expected after operand
prog.asm:60: error: comma, colon, decorator or end of line expected after operand
prog.asm:66: error: comma, colon, decorator or end of line expected after operand
prog.asm:71: error: comma, colon, decorator or end of line expected after operand
prog.asm:77: 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:84: error: comma, colon, decorator or end of line expected after operand
prog.asm:86: error: comma, colon, decorator or end of line expected after operand
prog.asm:92: error: comma, colon, decorator or end of line expected after operand
prog.asm:106: error: comma, colon, decorator or end of line expected after operand
prog.asm:155: error: comma, colon, decorator or end of line expected after operand
prog.asm:157: error: comma, colon, decorator or end of line expected after operand
prog.asm:159: error: comma, colon, decorator or end of line expected after operand
prog.asm:166: error: symbol `main' redefined
prog.asm:166: error: parser: instruction expected
prog.asm:168: error: parser: instruction expected
ld: cannot find prog.o: No such file or directory
stdout
Standard output is empty