Author Topic: Compare 4 byte string  (Read 8858 times)

Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
Compare 4 byte string
« on: January 17, 2021, 11:05:49 PM »
Sorry if this seems like a beginner question to some, but I want an easy way to compare a string in code space to a certain value without using extra segment registers. I'm doing this because I made my own DOS interrupt routine and I tacked on a string so a client program can identify it as the correct interrupt before calling it.

This is what I have so far:

Code: [Select]
;interrupt handler routine that's already loaded earlier in DOS as a .com file:

db 'INTERUPT' ;8 bytes
myinterrupt:
    ;Do interrupt function here....
iret

;And for the main routine that is loaded later and
interrupt_check:
mov CX,0h ;CX=interrupt status. 1=installed
mov AL,77h ;Assume int 77h points to our code above
mov AH,35h
int 21h ;ES:BX=handler
cmp BX,08h ;Make sure theres at least 8 characters in offset before entry point
jl notinstalled
push ES
pop DS
push BX
pop SI
sub SI,08h ;We make DS:SI = ES:BX minus 8 bytes
lodsd ;get first 4 letters of 8 in string
cmp EAX,'INTE'
jne notinstalled
lodsd ;get last 4 letters of 8 in string
cmp EAX,'RUPT'
jne notinstalled
mov CX,1h ;here all letters match
notinstalled:
ret


I'm not sure if the characters are incorrect because the byte-ordering messes me up. Maybe I need:

Code: [Select]
cmp EAX,'TEIN'

and

Code: [Select]
cmp EAX,'PTRU'

 instead?


Please let me know which way the letters go when scanning for them. Thanks.

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: Compare 4 byte string
« Reply #1 on: January 18, 2021, 12:37:37 AM »
You need to set the direction flag to know which way to read the string. "CLD" clears the direction flag, so the address is incremented when you use "LODSx" instruction, "STD" does the opposite. For your code, you need CLD before you use LODSD for the first time. Then you need ETNI and TPUR (in that order).

It might be easier to use CMPSD, as you already have the strings you are comparing in memory.
My graphics card database: www.gpuzoo.com