Question: Write a program that instead of you guessing the computers number, the computer tries to guess your number from 1 to 100. you think of
Write a program that instead of you guessing the computers number, the computer tries to guess your number from 1 to 100. you think of a number. computer takes a guess. you type "too high" or "too low" bases on that, the computer adjusts its guess. devise an algorithm that solves this in 10 or less steps. In Assembly Language. I need help adjusting the highest and lowest number range.
Here is my code so far:
include Irvine32.inc
.data
welcome BYTE "Welcome to my game! It is so cool.", 0
think BYTE "Think of a number between 1 and 100", 0
guess DWORD ?
lowest DWORD 1
highest DWORD 100
tries DWORD 0
guessIs BYTE "My guess is: ", 0
response BYTE 10 DUP(0)
directions BYTE "(yes) or no (too high / too low): ", 0
success BYTE "YAYYYY. I did it!", 0
yesStr BYTE "yes", 0
tooHighStr BYTE "too high", 0
tooLowStr BYTE "too low",0
triesStr BYTE "It only took ", 0
triesStr2 BYTE " tries.", 0
.code
main proc
mov edx, OFFSET welcome
call WriteString
call Crlf
mov edx, OFFSET think
call WriteString
call Crlf
;initial guess
mov guess, 50
TELLGUESS:
inc tries
mov edx, OFFSET guessIs
call WriteString
mov eax, guess
call WriteInt
call Crlf
mov edx, OFFSET directions
call WriteString
mov edx, OFFSET response
mov ecx, 9
call ReadString
INVOKE Str_compare, ADDR response, ADDR yesStr
je YES
INVOKE Str_compare, ADDR response, ADDR tooLowStr
je TOOLOW
INVOKE Str_compare, ADDR response, ADDR tooHighStr
je TOOHIGH
TOOLOW:
mov eax, guess
mov esi, highest
mov edi, lowest
mov edi, eax
add edi, esi
mov ebx, 2
mov eax, edi
xor edx, edx
div ebx
mov lowest, eax
mov guess, eax
mov lowest, eax
mov highest, esi
jmp TELLGUESS
TOOHIGH:
mov eax, guess
mov esi, highest
mov edi, lowest
mov esi, eax
add esi, edi
mov ebx, 2
mov eax, esi
xor edx, edx
div ebx
mov highest, eax
mov guess, eax
mov lowest, edi
jmp TELLGUESS
YES:
mov edx, OFFSET success
call WriteString
call Crlf
mov edx, OFFSET triesStr
call WriteString
mov eax, tries
call WriteInt
mov edx, OFFSET triesStr2
call WriteString
call Crlf
invoke ExitProcess,0
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
