Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Getting And Comparing Input
; How to call it from the program
call getinput
mov si, buffer
cmp byte[si], 0 ; Blank line
je main ; Ignore it
mov si, buffer
mov di, cmd_help ; Input compare: help
call strcmp
jc .help
mov si, buffer
mov di, cmd_hello ; Input compare: hello
call strcmp
jc .hello
mov si, err_cmd ; input entered is invalid
call printf
jmp main ; Infinity loop
mov si, msg_hello
call printf
jmp main
mov si, msg_help
call printf
jmp main
; The function
xor cl, cl
mov ah, 00h
int 16h ; Key press wait
cmp al, 08h ; Backspace key
je .backspace ; Handle
cmp al, 0dh ; Enter key
je .enter ; Handle
cmp cl, 3fh ; Inputted 63 characters
je .loop ; Only backspace and enter are accepted
mov ah, 0eh
int 10h
inc cl
jmp .loop
cmp cl, 0 ; Begin of the input
je .loop ; Ignore
dec di
mov byte[di], 0 ; Delete character
dec cl ; Decrementing the string counter
mov ah, 0eh
mov al, 08h
int 10h ; Print the backspace
mov al, ' '
int 10h ; Blank character
mov al, 08h
int 10h ; Backspace one more time
jmp .loop ; Goes back to the loop
mov al, 0 ; Null terminator
mov ah, 0eh
mov al, 0dh ; Enter character
int 10h
mov al, 0ah ; Newline character
int 10h
mov al, [si] ; Grab byte from SI
mov bl, [di] ; Grab byte from DI
cmp al, bl ; Compare if they are equal
jne .notequal ; They aren't equal
cmp al, 0 ; Both bytes are null
je .done
inc di ; Increment DI
inc si ; Increment SI
jmp .loop ; Start looping
clc ; Clear the carry flag
stc ; Set the carry flag
mov ah, 0eh
mov bh, 99h
or al, al
jz .return
int 10h
jmp .nextchar
cmd_help db "help", 0
msg_help db " Get help on our forums! :D", 0dh, 0ah, 0
cmd_hello db "hello", 0
msg_hello db " Hi all from Dream.In.Code!", 0dh, 0ah, 0
err_msg db "Input don't have any to compare.", 0dh, 0ah, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.