ok i dunno where to post this so i'm just gonna post it in here. ok how do i go about using this. because i'm reading AoA and its not telling me how i go about searching for files and stuff myself. can anyone help me plz. this seems to be the only thign i have problems with.
Posted on 2002-04-19 22:15:43 by Guy on ASM
In which chapter you are and which version of the book you have?
there are two versions (the old one for dos and the new one supporting win32 but using a special HLA syntax) ...
and what exactly do you mean by (searching files by yourself) ... I was reading the same book but I stopped and began reading win32asm tutorials ... you don't have to read the whole book ( Infact I think its better not to read the whole book so you don't get used to stuff that won't be so usefull later ) ... its enough to get the basics of assembly and masm from this book to get you started in win32asm world ...
good luck Guy ...:alright:
Posted on 2002-04-20 00:03:16 by code1101
sorry ...didn't pay attention to the subject ... your taking about interrupts ....hmmm ...
god I'm jelous of you man .... your very fast compared to me ... ( actually I never reached the interrupts ) ....:tongue:
Posted on 2002-04-20 00:27:33 by code1101
Well, I will try to explain this. In fact I've never used this function, I've just a complete help file where all the functions and interrupts are explained but this is all in French...

in:
AH = 4Eh
CX = File attribute
DX = Address of the buffer where there is the name of the file

out:
Flag Carry =0 : All right
Flag Carry =1 : Error
ax=2: path not found
ax=18:no file found with this specified attribute
Posted on 2002-04-20 09:38:43 by Vom-bonjour:-()
yes i have that part. but where does the name of the file found come up at. i need too know where i can find that at so i can finish up this program i'm making. does anyone know. and thanks man. i didn't know about those carries.

ack i have to edit this to make it more clear. ok when i search for the first file. and i find a file. where does the name of this file appear at. i don't think it comes up in any of the general purpose registers...
Posted on 2002-04-20 10:16:28 by Guy on ASM
Guy on Asm,
I'm assuming your targeting a dos platform, but one could theoretically use the int 21 service in a console program, or in a problem designed for wdosx, though these would be a great deal more complicated.
The basic approach behind using 21h services 4eh and 4fh is simple. 4eh is used to find the first file in the current or specified directory that matches particular attributes and file name specs. After 4eh call been issued, if it suceeds, then 4fh is used to find the next file in the directory that also matched. 4fh can be called repeatedly until no matching files remain.
For instance, lets say you wanted to obtain a list of all the files in the current directory with the extention .asm.

We begin by finding the first match by calling service 4eh.

mov cx, 0 ;set search attribute to normal files, no subdirs
mov dx, FileSpecs ; offset to a null terminated string
; containing "*.asm"
; ds must contain the segment
; from which the offset is relative
; but I will assume this is already so
mov ah, 4eh ; find first file
int 21h
jc error ;if carry flag set, jump to error
;ax hold the error code
Now, if no file matches "*.asm", the interupt with return with the
carry flag set, else it will store file information in the DTA(disk
tranfer area) By default, the DTA for your program is at offset
80h from your programs PSP segment. Under most circumstances
the PSP begins 100h (512) bytes before your program in memory,
but you can also obtain this segment with service 51h. This returns the PSP address in the BX register.

So at this point our DTA contains file info about the first file in the directory that matches our search parameters. Of interest to us at the moment is field 1Eh bytes into the DTA which contains the filename (DOS file name, not long file name) terminated with the null character (ascii 0). So the file name is at (PSPsegment:80h+1eh) or in other words (PSPsegment:9Eh)
So we can save the file name somewhere.

mov cx, 12 ; the file name will never be larger than 12
; bytes
mov di, Filename ; address to a 12 byte buffer
mov si, 9eh
mov ax, ; assuming we saved it previously
push ds ; save the data segment
push ds ;load es with ds
pop es ;like so
mov ds, ax ; set to PSP segment
cld ; clear direction flag
rep movsb ; copy 12 bytes
pop ds ;restore ds


To find the next file that matches *.asm, all we need to do is issue int 21h service 4fh. This will copy the info for the next file into the DTA. We can continue to do so until service 4fh sets the carry flag to indicate an error (usually ax = 12h to indicate no
more files match wild card.)
mov ah, 4fh
int 21h
jc Nomorefiles ;if carry, jump to Nomorefiles

Now, don't try a bit of that code under a protected mode operating system unless you really know what your doing, but under dos, thats the gist of searching for files.

Now, a lot of people will tell you that interupts and segments are a thing of thing of the past. The truth is that vacuum tubes are still used in our microwaves and interrupts are still integral to how our PCs work. Preemptive multitasking works through interrupts. Virtual memory relies on the Page fault exception, which is just a glorified interrupt. DPMI uses a software interrupt interface, so it can't hurt to get used to this stuff, so keep on reading AOA. Both of em, because there's good stuff in there.
Posted on 2002-04-20 10:34:36 by Canite
.model tiny
.stack 100h
.data
Error db "NO files found.$"
problem db "Unable to open file.$"
Beginning db "Searching for .txt files...",13,10,"$"
SearchLine db "*.txt",0
fhandle dw ?
FileName db ?
Daniel db "Daniel Millington$"
.code
Start:
mov ax,@data
mov ds,ax
mov es,ax
jmp Begin
NoFiles:
mov ah,09h
mov dx,offset Error
int 21h
jmp Quit
_Problem:
mov ah,09h
mov dx,offset problem
int 21h
jmp Quit
Begin:
mov ah,09h
lea dx,Beginning
int 21h
Searching:
mov ah,4eh
lea dx,SearchLine
int 21h
cmp ax,18
je NoFiles
Found: ;<==== heres my problem right here
mov ah,3dh ;<=== i dunno how to get the file name
mov al,1 ;<=== that is in the psp. =(
int 21h
jc _Problem
xchg bx,ax
mov fhandle,ax
Write:
mov ah,40h
mov cx,17
mov dx,offset Daniel
int 21h
Close:
mov ah,4ch
int 21h
Quit:
mov ah,4ch
int 21h
end Start

could someoen plz help me :confused:
Posted on 2002-04-20 12:00:04 by Guy on ASM
hi,

First set DTA addr to new addr. Fn 4e stores filename, attr, and other data to DTA adress.

Like this:





;.386
seg_a segment byte public
assume cs:seg_a;ds:seg_a

org 100h
start:
jmp basla

;This DTA start----------------------------------
dta db 15h dup (0)
attr db 00
ftime dw 00
fdate dw 00
filename db 13 dup(0)
;DTA end-----------------------------------------

wildcard db '*.*',00
crlf db 0dh,0ah,'$'

currdir db 'Listenen surucu ve yol : '
drive db 00
db ':\'
path db 64 dup (00),0dh,0ah


dosyaadi db 8 dup (' ')
aralik db 4 dup (' ')
dosyaadi2 db 3 dup (' ')


basla:
push cs
push cs
pop ds
pop es

mov ah,19h ; Get Current Driver
int 21h
mov dl,al
add al,'A'
mov byte ptr [drive],al
inc dl
mov ax,4700h
lea si,path
int 21h
mov ah,40h
mov cx,60
xor bx,bx
lea dx,currdir
int 21h
call procrlf

mov ax,1a00h ; al=0 Set, al=1 Get DTA address
lea dx,dta ; New DTA
int 21h
dir1:
mov ax,4e00h
lea dx,wildcard ; wildcard
mov cx,00h ; listed attribt
int 21h

call convert ; convert any

mov ah,4fh ; search next file
lea dx,dta ; DTA
int 21h
cmp al,12h ;error code 12 = file empty
jnz dir1

convert:
mov ah,40h
mov bx,0
mov cx,13
lea dx,dta+1eh
int 21h
call procrlf
ret

procrlf:
lea dx,crlf
mov ah,09
int 21h
ret


cikis: int 20h


seg_a ends
end start



have nice days,
Posted on 2002-04-20 19:53:43 by CYDONIA
thank u. dunno how i can do all these other functions but not search. well thank u. i'll have more question dealing with win32 pretty soon =)
Posted on 2002-04-20 21:40:16 by Guy on ASM