Basic choice command in Assembly

So this is pretty much like the choice command, not as advanced though. The only arguments you provide is a list of characters that the user can press as a choice. Just like the choice command, during the choice prompt it will keep looping for a character input until the user presses a valid key, that is, a one of the keys that you have specified in the list as the arguments.
(compile with fasm):

format MZ
mov si,0082h
xor cx,cx
xor dx,dx
mov dl,[si]
cmp dl,0dh
je main
inc ch
inc si
jmp getargc
mov bx,count
mov byte [bx],ch
mov ax,0800h
int 21h
call validate
cmp dh,00
jne input
mov ah,4ch
mov al,cl
int 21h
mov si,0081h
mov bx,count
mov ch,byte [bx]
cmp cl,ch
je exvloop
inc si
inc cl
cmp al,[si]
je success
jmp vloop
xor cx,cx
mov dh,01
mov dh,00

count db 00

Usage example:

@echo off
echo Type a number from 1 to 5
choice 12345
echo You chose %errorlevel%

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: