Professional Documents
Culture Documents
Assembly Code For Intel 8086 For Guessing Game
Assembly Code For Intel 8086 For Guessing Game
GROUP 8
Develop a Guessing Game where the client is given five trials to guess a randomly selected word
from a pool. If correct guess, ‘congratulations’ displayed and a score given depending on trial
number. Incorrect guess records a zero score for that particular attempt. Failure to have a
correct guess over the trails, ‘Please try again’ but a new guess word is selected from the pool.
.model small
.data
word_array db "lunch", "every", "maybe", "clown", "towel", "solid", "stone", "house", "ebony",
"other" , "$"
options_display db "lunch,every,maybe,clown,towel,solid,stone,house,ebony,other$"
close_message db "Goodbye!$"
try_command db 'p'
exit_command db 'q'
word_size db 5
trials_count db 5
word_index db 1
word_count db 10
temp_index db ?
trials_count_pre db "Trials remaining:$"
guess_status db 0
.code
get_indexed_char:
mov [di], bx
inc si
inc di
loop get_indexed_char
ret
get_indexed_word:
mov si, bx
mov cx, 0
call get_indexed_char
ret
get_selected_word:
mov al, 1
mul word_index
mul word_size
add bx, ax
call get_indexed_word
ret
display_options:
call new_line
int 21h
call new_line
ret
init_word_index:
mov bl, 0
mov word_index, bl
call get_selected_word
jmp get_command
inc_word_index:
mov bl, 5
mov trials_count, bl
add bl, 1
je init_word_index
mov word_index, bl
call get_selected_word
jmp get_command
compare_char:
cmp bl, bh
jne wrong_guess
inc si
inc di
loop compare_char
jmp correct_guess
ret
compare_word:
mov cx, 0
call compare_char
ret
correct_guess:
int 21h
call print_score
call new_line
jmp close
wrong_guess:
int 21h
call new_line
dec bl
mov trials_count, bl
cmp trials_count, 0
je trials_ended
jmp get_word
read_char:
int 21h
ret
read_string:
call read_char
mov [si], al
inc si
loop read_string
ret
print_trials_count:
call new_line
int 21h
add dl, 48
int 21h
call new_line
ret
print_score:
add dl, 48
int 21h
call new_line
ret
print_selected_word:
int 21h
int 21h
call new_line
ret
print_word:
int 21h
int 21h
ret
get_command:
int 21h
int 21h
call new_line
je play
jmp close
play:
int 21h
call new_line
call display_options
jmp get_word
get_word:
call print_trials_count
int 21h
mov cx, 0
call read_string
call new_line
call print_word
call new_line
call compare_word
new_line:
int 21h
ret
trials_ended:
call new_line
mov ah, 09h
int 21h
call new_line
jmp inc_word_index
close:
call new_line
int 21h
mov ah, 00
int 20h
main:
mov ds, ax
call get_selected_word
; call select_word
; call print_selected_word
jmp get_command
end main