Compare a STRING

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Berry

Compare a STRING

Post by Berry »

hello

I wanna use cmpsb to compare a string in memory whith one I defined. But I don't know how to define a string :S Tried this

first_kernel_file_letter db 'k'

but it wont compile...
common

RE:Compare a STRING

Post by common »

string db 'blah', 0

should work, what assembler are you using?
Berry

RE:Compare a STRING

Post by Berry »

srry, I was doing something else wrong. I used cmpsb like this

mov al, [es:bx]
cmpsb al, [string]

the docs sait it work, but it seems that I have to do it like this

mov al, [es:bx]
mov si, ax
mov di, string
cmpsb

now, it can't find the thing. I'm reading out the root directory, using LBACHS to calculate the location of the root dir. But it can't find the file... Is my method of seaching wrong, or something else? The file I search (which I've pasted on the diskette) I've defined like this

file db 'file     bin'

is that wrong? The file name is 8 chars long, than a space and then a three chars long extension...
Adek336

RE:Compare a STRING

Post by Adek336 »

try
file db 'FILE    BIN' because the name is uppercase.
ASHLEY4

RE:Compare a STRING

Post by ASHLEY4 »

;Try this:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Looks for a file with particular name ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Input:  DS:SI -> file name (11 chars) ;;
;;        ES:DI -> root directory array ;;
;;        DX = number of root entries  ;;
;; Output: SI = cluster number          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

FindName:
        mov    cx, 11
FindNameCycle:
        cmp    byte [es:di], ch
        je      FindNameFailed          ; end of root directory
        pusha
        repe    cmpsb
        popa
        je      FindNameFound
        add    di, 32
        dec    dx
        jnz    FindNameCycle          ; next root entry
FindNameFailed:
        jmp    ErrFind
FindNameFound:
        mov    si, [es:di+1Ah]        ; si = cluster no.
JAAman

RE:Compare a STRING

Post by JAAman »

there should NOT be a space between the fileName and ext -- it should be a total of:

8 char (fileName)+ 3 char(ext)=11 characters TOTAL not 12!

also the filename should be ALLCAPS (since FAT12 dir entries are always in capital letters to make searching easier)
Post Reply