flat assembler
Message board for the users of flat assembler.

Index > DOS > Case insesitive comparison

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Hello,
I wrote this simple routine, it searches for a null terminated string inside another null terminated string.
Comparison is case-sensitive, and i want to know which is the faster way to compare ah,al but case insesitive.
Also, in Dos, how can i place on a buffer the application path, for example 'C:\FASM\xxx.exe'
Thanks in advance, for your time.

Code:
;BX = string to search inside
;DX = string to search for
;AX = return position, 0 if not found
STRFIND:
PUSH BX CX DX SI DI
MOV CX,1
@1:
MOV AL,BYTE [BX]
TEST AL,AL
JE @3
MOV SI,BX
MOV DI,DX
@2:
MOV AH,BYTE [DI]
TEST AH,AH
JE @4
TEST AL,AL
JE @3
CMP AH,AL
JNE @F
INC DI
INC SI
MOV AL,BYTE [SI]
JMP @2
@@:
INC CX
INC BX
JMP @1
@3:
XOR CX,CX
@4:
MOV AX,CX
POP DI SI DX CX BX
RET
    
Post 10 May 2007, 19:54
View user's profile Send private message Reply with quote
eek



Joined: 21 Oct 2006
Posts: 24
eek
Post 11 May 2007, 02:29
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
thank you eek for the link, it's what i was looking for.

I change:
Code:
ax,es:[002Ch]
    

to
Code:
mov ax,[es:002Ch]
    


I found some more interesting scripts and articles there!

If anyone can help me with my first question, hope it make sence, my English are not very good.. Embarassed
Post 11 May 2007, 17:18
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
This isn't directly an answer (sorry), but for a quick hack / hint, see my AV (.ZIP viewer) proggie.

Code:
and al,0DFh ; uppercase
or al,20h     ; lowercase
xor al,20h   ; toggle case
    
Post 24 May 2007, 05:51
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Thank you rugxulo.
Fasm forum has a lot of interesting stuff. It's great to explore. Razz
Post 24 May 2007, 20:19
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
I came up to this so far, now comparison is case insensitive.

Code:
;BX = string to search inside
;DX = string to search for
;AX = return position, 0 if not found
STRFIND:
PUSH BX CX DX SI DI
MOV CX,1
@1:
MOV AL,BYTE [BX]
TEST AL,AL
JE @3
MOV SI,BX
MOV DI,DX
@2:
MOV AH,BYTE [DI]
TEST AH,AH
JE @4
TEST AL,AL
JE @3
CMP AH,AL
JE @EQ
AND AX,0DFDFH
CMP AX,4141H
JL @NE
CMP AX,5A5AH
JA @NE
CMP AH,AL
JNE @NE
@EQ:
INC DI
INC SI
MOV AL,BYTE [SI]
JMP @2
@NE:
INC CX
INC BX
JMP @1
@3:
XOR CX,CX
@4:
MOV AX,CX
POP DI SI DX CX BX
RET 
    
Post 30 May 2007, 18:37
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
do not forget: "or al,20h" will not help for national characters
Post 31 May 2007, 04:17
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
If you return 0 if not found, what will you return if the substring is found at position 0 (immediate start of string)? I had the same problem, actually. I just ended up using -1 for error (safer than 0, at least, right?).

P.S. shoorick is right, of course, so keep that in mind.
Post 31 May 2007, 05:02
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Thank you both for your comments.
rugxulo i'm counting from 1 for that reason.
Post 31 May 2007, 16:51
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
A simple routine i wrote for a friend's school project.
It's a string read routine that stores user input on a variable as a null terminated string.
It also handles the backspace key and returns on CX number of chars.
Code:
ORG 100H

MOV DI,BUFFER
CALL STRREAD
INT 20H

STRREAD:
PUSH AX DI                                          
XOR CX,CX                
INPUT:               
MOV AH,01H             
INT 21H                    
CMP AL,0DH                 
JE EXIT   
CMP AL,08H                 
JE BACKSPACE          
STOSB                     
INC CX                    
JMP INPUT
BACKSPACE:
CMP CX,0                  
JE ERROR           
MOV AL,20H
INT 29H                  
MOV AL,08H               
INT 29H                  
DEC CX                 
DEC DI                     
JMP INPUT
ERROR:                           
MOV AL,20H             
INT 29H                  
JMP INPUT                        
EXIT:
XOR AL,AL
STOSB               
POP DI AX                      
RET

BUFFER DB 100 DUP (?)
    
Post 23 Jul 2007, 17:26
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
thimis, try jcxz Error to save three bytes.

(Also, try indenting your instructions, easier to distinguish from labels. And using ' ' looks more readable than 20h.)
Post 25 Jul 2007, 03:31
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
nice tips, thanks rugxulo.
Post 25 Jul 2007, 16:17
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.