You are on page 1of 8

ASSIGNMENT TWO

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$"

linefeed db 13, 10, "$"

word_prompt db "Enter any 5 letter word from the options below:$"

command_prompt db "Enter 'p' to play or 'q' to quit:$"

close_message db "Goodbye!$"

wrong_guess_message db "Wrong guess!!:$"

correct_guess_message db "Congratulations, correct guess!. Score :$"

try_command db 'p'

exit_command db 'q'

word_input_pre db "Enter word:$"

word_input_post db "You entered :$"

word_input db 5 dup(?), "$"

selected_word db 5 dup(?), "$"

selected_word_pre db "Selected word:$"

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:$"

trials_ended_pre db "Trials ended!! Try again$"

guess_status db 0

.code

get_indexed_char:

mov bx, [si]

mov [di], bx

inc si

inc di

loop get_indexed_char

ret

get_indexed_word:

mov si, bx

mov di, offset selected_word

mov cx, 0

mov cl, word_size

call get_indexed_char

ret

get_selected_word:

mov bx,offset word_array

mov al, 1

mul word_index

mul word_size

add bx, ax

call get_indexed_word

ret

display_options:
call new_line

mov ah, 09h

mov dx, offset options_display

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

mov bl, word_index

add bl, 1

cmp bl, word_count

je init_word_index

mov word_index, bl

call get_selected_word

jmp get_command

compare_char:

mov bl, [si]

mov bh, [di]

cmp bl, bh

jne wrong_guess

inc si

inc di
loop compare_char

jmp correct_guess

ret

compare_word:

mov si, offset word_input

mov di, offset selected_word

mov cx, 0

mov cl, word_size

call compare_char

ret

correct_guess:

mov ah, 09h

lea dx, correct_guess_message

int 21h

call print_score

call new_line

jmp close

wrong_guess:

mov ah, 09h

lea dx, wrong_guess_message

int 21h

call new_line

mov bl, trials_count

dec bl

mov trials_count, bl

cmp trials_count, 0

je trials_ended

jmp get_word
read_char:

mov ah, 01h

int 21h

ret

read_string:

call read_char

mov [si], al

inc si

loop read_string

ret

print_trials_count:

call new_line

mov ah, 09h

lea dx, trials_count_pre

int 21h

mov ah, 02h

mov dl, trials_count

add dl, 48

int 21h

call new_line

ret

print_score:

mov ah, 02h

mov dl, trials_count

add dl, 48

int 21h

call new_line
ret

print_selected_word:

mov ah, 09h

lea dx, selected_word_pre

int 21h

mov ah, 09h

lea dx, selected_word

int 21h

call new_line

ret

print_word:

mov ah, 09h

lea dx, word_input_post

int 21h

mov ah, 09h

lea dx, word_input

int 21h

ret

get_command:

mov ah, 09h

lea dx, command_prompt

int 21h

mov ah, 01h

int 21h

cmp al, try_command

call new_line

je play

jmp close
play:

mov ah, 09h

lea dx, word_prompt

int 21h

call new_line

call display_options

jmp get_word

get_word:

call print_trials_count

mov si, offset word_input

mov ah, 09h

lea dx, word_input_pre

int 21h

mov cx, 0

mov cl, word_size

call read_string

call new_line

call print_word

call new_line

call compare_word

new_line:

mov ah, 09h

mov dx, offset linefeed

int 21h

ret

trials_ended:

call new_line
mov ah, 09h

lea dx, trials_ended_pre

int 21h

call new_line

jmp inc_word_index

close:

call new_line

mov ah, 09h

lea dx, close_message

int 21h

mov ah, 00

int 20h

main:

mov ax, @data

mov ds, ax

call get_selected_word

; call select_word

; call print_selected_word

jmp get_command

end main

You might also like