We have been given this project and I was wondering if someone could make my algorithm better using TASM and DOSBox.
This is what I have done so far:
ideal
model small
stack 10244
dataseg
msg1 db 'Enter Word: $'
msg2 db 'Enter Hint: $'
msg3 db 'Enter Guess(Press . to end guess)($'
wrnmsg db 'Wrong!$'
a3msg db 'Number of letters: $'
a4msg db 'First two letters: $'
a5msg db 'Last letter: $'
a6msg db 'Second to the last letter: $'
fail db ' Enter guess again($'
secret db 21 dup('')
hint db 101 dup('')
guess db 21 dup('')
endss db '): $'
win db 'That is correct! You win!$'
lose db 'Im sorry you lose$'
cnt dw 0
codeseg
PROC compare
mov bx, 0
mov di, 0
loop1:
mov al, [secret+di]
mov ah, [guess+di]
cmp ah, al
jne no
cmp al, '$'
je endi
no:
mov bx, 1
endi:
ret
ENDP
PROC main
mov ax, @data
mov ds, ax
mov es, ax
lea dx, [msg1]
mov ah, 9
int 21h
mov bx, 0
scan:
mov ah, 1
int 21h
cmp al, '.'
je com
inc [cnt]
mov [secret+bx], al
inc bx
jmp scan
com:
mov [secret+bx], '$'
mov dx, 10
mov ah, 2
int 21h
lea dx, [msg2]
mov ah, 9
int 21h
lea dx, [hint]
mov ah, 10
int 21h
mov dx, 10
mov ah, 2
int 21h
lea dx, [msg3]
mov ah, 9
int 21h
lea dx, [hint]
mov ah, 9
int 21h
lea dx, [endss]
mov ah, 9
int 21h
mov cx, 0
loop2:
inc cx
mov bx, 0
scan2:
mov ah, 1
int 21h
cmp al, '.'
je com2
mov [guess+bx], al
inc bx
jmp scan2
com2:
mov [guess+bx], '$'
mov dx, 10
mov ah, 2
int 21h
call compare
cmp bx, 0
je right
lea dx, [wrnmsg]
mov ah, 9
int 21h
cmp cx, 3
je three
cmp cx, 4
je four
cmp cx, 5
je five
cmp cx, 6
je six
cmp cx, 7
je fail
man:
mov dx, 10
mov ah, 2
int 21h
lea dx, [fail]
mov ah, 9
int 21h
lea dx, [hint]
mov ah, 9
int 21h
lea dx, [endss]
mov ah, 9
int 21h
jmp loop2
right:
lea dx [win]
mov ah, 9
int 21h
jmp end1
fail:
lea dx, [lose]
mov ah, 9
int 21h
jmp end1
three:
lea dx, [a3msg]
mov ah, 9
int 21h
lea dx, [cnt]
mov ah, 2
int 21h
jmp man
four:
lea dx, [a4msg]
mov ah, 9
int 21h
mov di, 0
mov si, 1
mov dh, [secret+di]
mov ah, 2
int 21h
mov dh, [secret+si]
int 21h
jmp man
five:
lea dx, [a5msg]
mov ah, 9
int 21h
mov di, [cnt]
mov dl, [secret+di]
mov ah, 2
int 21h
jmp man
six:
lea dx, [a6msg]
mov ah, 9
int 21h
mov di, [cnt]
dec di
mov ah, 2
int 21h
jmp man
end1:
mov ah, 4ch
int 21h
ENDP
END main
What was required of us was a program that will simulate a guessing game where the first player will input the word to be guessed by the second player including a hint such as what category and other description. (Description can have a maximum of 100 characters).
The second player will be given 6 chances to guess. If in the third try, the 2nd player still cannot guess the word, hints will be given for the succeeding unsuccessful guesses as cited below:
- Third unsuccessful try – Number of letters will be displayed on screen
- Fourth unsuccessful try – First two letters will be revealed
- Fifth unsuccessful try – Last letter will be revealed
- Sixth unsuccessful try- Second to the last letter will be revealed