flat assembler
Message board for the users of flat assembler.

Index > OS Construction > help with cmp strings

Author
Thread Post new topic Reply to topic
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 29 Aug 2007, 03:37
I am having trouble comparing strings.. str1 is the inputed string
if I enter '-' it returns noprob

it should only return noprob if I enter -help / -dir / -copy
am I going about this wrong?
Is there a better way of comparing strings?

Like dos- if [key word] go to noprob if not print error and continue..

noprob: is my check point to see if its working :prints valid command!
and continues..

Also I no its not the inputed data str1 - I have verified it by out putting it to the screen

help db '-help'
db 0
dir db '-dir'
db 0
copy db '-copy'
db 0


Code:
mov si,str1
mov di,help
repe cmpsb
test cx,cx

je noprob
jmp con1


con1:

mov si,str1
mov di,dir
repe cmpsb
test cx,cx

je noprob
jmp con2

con2:
mov si,str1
mov di,copy
repe cmpsb
test cx,cx

je noprob
jmp error

error:
mov si,consoleError
call printstr
jmp cont
    


Thanks in advance for any help!
Post 29 Aug 2007, 03:37
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 29 Aug 2007, 03:51
Take a look at my MiniDos demo/tut, it has full commented code to do what you want: http://board.flatassembler.net/topic.php?t=5275&start=0
quick example
Code:
;====================================================;;  CLS.            compare command buffer with 'cls' ;;====================================================;        mov   si,CommandBuffer              ; Move the address of CommandBuffer in SI        mov   cx,4                          ; Move number of letters into CX        mov   di,cCLS                       ; Point to label        repe  cmpsb                         ; Test if =.        jne   not_cls                       ; If not =, jump to label not_cls        call  Cls                           ; call our function        call  Cursor                        ; call our function        call  Welcome                       ; call our function        jmp   ExitFound                     ; Jump to label ExitFoundnot_cls:;====================================================;;  TIME.          compare command buffer with 'time' ;;====================================================;        mov   si,CommandBuffer              ; Move the address of CommandBuffer in SI        mov   cx,5                          ; Move number of letters into CX        mov   di,cTIME                      ; Point to label        repe  cmpsb                         ; Test if =.        jne   not_time                      ; If not =, jump to label not_time        call  Time                          ; call time function        jmp   ExitFound                     ; Jump to label ExitFoundnot_time:;more stuff herecCLS            db 'CLS',0cTIME           db 'TIME',0    

Note: you need to convert them to uppercase before testing, just in case they write them in upper case.
Post 29 Aug 2007, 03:51
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 29 Aug 2007, 05:17
TY - The problem was I was using bx to count the number of chars entered and was moving it into cx...and then comparing them...
I altered my code to mov cx,5 for -help and so on and it works great!
Post 29 Aug 2007, 05: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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.