Very Simple guessing game in asm

In this game you have to guess a number from 0 to 9. See if you can figure out the advanced random number generating algorithm I used in this code :lol:.

Assemble with fasm

org 100h
use16
mov ah,9
mov dx,prompt
int 21h
mov ax,0800h
int 21h
mov dl,al
mov ah,02h
int 21h
sub al,30h
mov bh,al
mov ax,2c00h
int 21h
mov ax,0900h
cmp dh,0ah
jge adjust
continue:
mov bl,dh
cmp dh,bh
jne wrong
mov dx,cmsg
int 21h
jmp exit
wrong:
mov dx,wmsg
int 21h
jmp exit
adjust:
sub dh,0ah
cmp dh,0ah
jge adjust
jmp continue
exit:
mov dx,answ
int 21h
mov dl,bl
add dl,30h
mov ah,02
int 21h
mov ax,0900h
mov dx,crlf
int 21h
mov ax,4c00h
int 21h
prompt db "I'm thinking of a number from 0 to 9: $"
cmsg db 0dh,0ah,0dh,0ah,"Correct!",0dh,0ah,"$"
wmsg db 0dh,0ah,0dh,0ah,"Wrong!",0dh,0ah,"$"
answ db "The answer was: $"
crlf db 0dh,0ah,"$"

Also if you have a 32-bit windows os you can just run this batch file which uses debug to automatically create the program:

@echo off
REM For 32-bit Windows only. (See Computer Properties)
REM Program will be created in current directory.
REM Do not directly open program, run from
REM cmd or dos.
REM --------------------
REM Set name of game
REM Cannot be more than 8 characters
set name=comgame
REM --------------------
(
echo a 100
echo mov ah,09
echo mov dx,015c
echo int 21
echo mov ax,0800
echo int 21
echo mov dl,al
echo mov ah,02
echo int 21
echo sub al,30
echo mov bh,al
echo mov ax,2c00
echo int 21
echo mov ax,0900
echo cmp dh,0a
echo jge 0137
echo mov bl,dh
echo cmp dh,bh
echo jnz 0130
echo mov dx,0183
echo int 21
echo jmp 0141
echo mov dx,0192
echo int 21
echo jmp 0141
echo sub dh,0a
echo cmp dh,0a
echo jge 0137
echo jmp 0123
echo mov dx,019f
echo int 21
echo mov dl,bl
echo add dl,30
echo mov ah,02
echo int 21
echo mov ax,0900
echo mov dx,01b0
echo int 21
echo mov ax,4c00
echo int 21
echo db "I'm thinking of a number from 0 to 9: $"
echo db 0d,0a,0d,0a,"Correct!",0d,0a,"$"
echo db 0d,0a,0d,0a,"Wrong!",0d,0a,"$"
echo db "The answer was: $"
echo db 0d,0a,"$"
echo.
echo rcx
echo 00b3
echo n %name%.com
echo w
echo q
)>>makegame.dbg
debug<nul
del makegame.dbg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: