Write a (Irvine Assembly) program to generate a random number between 0 and 100,
ID: 3713843 • Letter: W
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 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
Explanation / Answer
386 02 .model flat,stdcall 03 .stack 4096 04 ExitProcess PROTO, dwExitCode:DWORD 05 Writestring PROTO 06 RandomRange PROTO 07 Randomize PROTO 08 crlf PHOTO 09 gotoxy PROTO 10 11 .data 12 message byte "Random number Generator Game",0 13 mesg 2 byte "You Ten changes to guess the right number!",0 14 mesg 3 byte "Good Luck",0 15 getnum byte "Enter your guess? ",0 16 toohi byte "Your number is too large!",0 17 toolo byte "Your number is too small", 0 18 right byte "You got it",0 19 20 .code 21 Main PROC 22 call Randomize 23 mov eax, 99 24 Call RandomRange 25 add eax, 1 26 mov Guess, AEX 27 28 mov dh, 2 29 mov dl, 25 30 call gotoxy 31 mov edx, offset Message 32 call writeString 33 34 mov dh, 6 35 mov dl, 29 36 call gotoxy 37 mov edx, offset message 38 call Writestring 39 40 mov dh, 6 41 mov dl, 22 42 call writeint 43 44 mov eax 500 45 call delay 46 call crlf 47 call waitmsg 48 49 call clrscr 50 51 mov exc, 10 52 53 L1: 54 move edx, getnum 55 call writestring 56 57 58 59 L2: 60 61 62 INVOKE EXitProcess, 0 63 main ENDP 64 END MAin
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.