Question: Write a (Irvine Assembly) program to generate a random number between 0 and 100, then prompt the user to guess a number between 0 and
Write a (Irvine Assembly) program to generate a random number between 0 and 100, then prompt the user to guess a number between 0 and 100. Tell the user whether the number is higher, lower, or correct. (100 is too high or 50 is too low). Continue to allow the user to guess until they get the correct number. Once they have the correct value, ask them if they would like to play again. If yes, clear the display and start over. If no, exit the program.
I can generate the random number but I am not sure how to write the loops to compare if the number is high, low or correct and output with the correct prompt. Can someone help me out?
INCLUDE Irvine32.inc
.data
;--------- Enter Data Here
vName byte "Jason Brotherson", 0
vPrompt byte "Guess a number between 0 and 100: ", 0
vPromptLow byte "The number you guessed was low. Please guess again: ", 0
vPromptHigh byte "The number you guessed was high. Please guess again: ", 0
vPromptCorrect byte "The number you guessed was correct.", 0
VPromptAgain byte "Would you like to play again? ", 0
.code
main PROC
;--------- Enter Code Below Here
call clrscr
call DisplayName
call DisplayPrompt
call DisplayDate
ret
DisplayName:
mov dh, 6
mov dl, 0
call Gotoxy
mov edx, offset vName
call WriteString
ret
DisplayPrompt:
mov dh, 8
mov dl, 0
call Gotoxy
mov edx, offset vPrompt
call WriteString
call ReadDec ;Reads random number
;Generates a random number;
Loop:
call Randomize
mov eax, 101 ;stores the random number between 1 and 100 in eax
call RandomRange
call WriteDec
mov edx, offset vCarriageReturn ;Writes the number on the next line after a guess
call WriteString
cmp eax, 99 ;loops until the number 99 is generated
jnz Loop
xor ecx, ecx
call ReadChar
exit
main ENDP
END main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
