Yesterday, we got a string of text from the user. Today, we'll learn how to do a case
insensitive comparison of 2 strings. However, there's a catch, these strings must be NULL
terminated (end with a 0 byte instead of a $). So instead of putting a $ on the end like
last time, we'll put a 0 at the end.
Patater GBAGuy Mirror
Service 2Fh is the Multiplex Service. It allows communication between Windows and DOS.
We'll be using Function 121Eh to compare strings. That's right, a 16bit number. For 16bit function
numbers, all of AX is the function number.
How to use Function 121Eh
Here's our input again and move down a lines:
mov dx,offset len
This puts a 0 at the end making a NULL-terminated string.
mov bx,offset act
mov dx,offset buffer
add dl,byte [bx]
mov byte [bx],0 ; note that the zero was $ last time
Here we do the comparison:
mov ax,offset msg ; compare input with msg variable
mov si,ax ; SI is the first string
mov ax,offset buffer
mov di,ax ; DI is the second string, it shouldn't matter what order.
mov ax,121Eh ; function number
int 2Fh ; call Multiplex Service
je Yep ; if strings equal goto Yep
jmp Nope ; goto Nope
mov dx,offset good
int 21h ; tell the user it's good
int 21h ; exit
mov dx,offset bad
int 21h ; tell user no match
int 21h ; exit
len db 255
act db 0
buffer db 256 DUP 0
msg db "Elmo",0
bad db "How can you not say 'Elmo'!$"
good db "I like Elmo too!$"
And they say ASM is hard!? If you don't get it, ask me!
This Day In Review
Everyone always wants to compare strings, so here you go!
Have some fun with this!,
Intro - Day 16