; Display the program title and programmer’s name. Then get the user’s name, and greet the user.
; 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].
; Get and validate the user input (n).
; Calculate and display all of the Fibonacci numbers up to and including the nth term.
; 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)
; Display a parting message that includes the user’s name, and terminate the program.
; 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
;defined constant for upper limit of Fibonacci terms
FIBSTERM = 47
.data
caption db"Fibonacci Numbers",0;Message Box (Do something incredible for me!)
HelloMsg BYTE"Welcome to Fibonacci Number for Fun!",0dh,0ah
BYTE"Click OK to Begin",0
title1 BYTE" Fibonacci Numbers",0
title2 BYTE" Programmed by Riam S. Kidd",0
rules1 BYTE"Enter the number of Fibonacci terms to be displayed",0
rules2 BYTE"Give the number as an integer in the range [1 .. 46].",0
askName BYTE"What's your name? ",0
userName BYTE33 DUP(0);string to be entered by user
greetUser BYTE"Nice to meet you, ",0
askFibnum BYTE"How many Fibonacci terms do you want? ",0
invalidNum BYTE"That's an invalid number. Please enter a number in the range of 1 and 46.",0
goodBye BYTE"Have a Nice Day! Good-Bye ",0
exclaim BYTE" ! ",0
fibsNum DWORD ? ;get number of Fib terms to display from user
dNum DWORD ?
remainNum DWORD ?
.code
main PROC
;Message Box Display
movebx,OFFSET caption
movedx,OFFSET HelloMsg
call MsgBox
;Display title 1: Fibonacci Numbers
moveax, green +(black*16);sets text color to green
call SetTextColor
movedx,OFFSET title1 ;set up for call to WriteString
call WriteString
call Crlf
call Crlf
;Display title 2: programmer's name
moveax, white +(black*16);sets text color back to white
call SetTextColor
movedx,OFFSET title2
call WriteString
call Crlf
call Crlf
;Display instructions line 1
movedx,OFFSET rules1
call WriteString
call Crlf
;Display instructions line 2
movedx,OFFSET rules2
call WriteString
call Crlf
call Crlf
;Get user name
movedx, OFFSET askName
call WriteString
movedx, OFFSET userName
movecx,32
call ReadString
;Greet user by name
movedx, OFFSET greetUser
call WriteString
movedx, OFFSET userName
call WriteString
call Crlf
;get number of Fib terms to display from user
input:
movedx,OFFSET askFibnum
call WriteString
call ReadInt
mov fibsNum,eax
call Crlf
;validate user input
decide:
moveax, fibsNum
cmpeax, FIBSTERM ;check condition that input is not greater than 47
jge greater ;out of bounds input
jl initial ;go to intial if Fib terms are acceptable
greater:
movedx, OFFSET invalidNum ;displays message if user input is invalid and reminds user to enter correct number within range
call WriteString
call Crlf
call Crlf
jmp input ;prompts user to start again
call Crlf
;initializing Fibonacci sequence -- if this is not in place it doesn't calculate correctly
initial:
moveax, white +(green*16); white on green background -- highlights Fibonacci printout
call SetTextColor
movebx,1; initial setup
movedx,0
movecx, fibsNum ; get number of Fib
;loop calculating and printing Fibonacci sequence
L1:
moveax,ebx
addeax,edx
movebx,edx
movedx,eax
call WriteDec ;print out Fibonacci numbers
moval, TAB ;horizontal tab
call WriteChar ;write the tab displays it aligned
loop L1 ;subtract 1 from ecx, if ecx !=0, goes to L1. reach 0 terminates loop
moveax, white +(green*16);white on green background
call SetTextColor
;Put code as comment because it won't make new line after 5 characters.
;I tried but failed to make it work.
;L2:
;mov eax, 1 ;define counter variable has initial value of 1.
;cdq
;mov ebx, 5 ; divide by 5
;div ebx
;inc eax ; remainder incremented if != 0
;mov dNum, eax
;mov remainNum, edx
;cmp remainNum, 0 ;if remainer is not equal to 0 then counter is incremented
;cmp eax, fibsNum ;checks if ebx (counter is greater than fibsNum. If it is then loop terminates. If less then loops.
;jle L2
moveax, white +(black*16); white on black background -- goes back to default color and background
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