MINISTERUL EDUCAŢIEI sI sTIINŢEI
AL REPUBLICII
UNIVERSITATEA TEHNICA A MOLDOVEI
Facultatea: CIM
Catedra: Tehnica de Calcul
LUCRARE DE LABORATOR NR.4
Tema: Resurse de sistem de gestiune a fisierelor, directoarelor si discurilor
A eleborat: st. grupei
A verificat: profesor
CHISINAU 2004
Scopul lucrarii: studierea sistemului de intreruperi al calculatoarelor personale IBM PC si a sistemului de gestiune a fisierelor, a sistemului de operare MS-DOS.
Sarcina pentru lucrarea de laborator:
CreateFile MACRO Handle, fileName
mov ah, 3Ch
mov cx, 20h
mov dx, offset fileName
int 21h
mov [Handle], ax
ENDM
OpenFile MACRO Handle, fileName
LOCAL E
mov ah, 3Dh
mov dx, offset fileName
mov al, 02h
int 21h
mov [Handle], ax
cmp ax, 02h
jne E
CreateFile Handle, fileName
E:
ENDM
CloseFile MACRO Handle
mov ah, 3Eh
mov bx, Handle
int 21h
ENDM
Seek MACRO Handle, pos
push cx
push dx
xor cx, cx
mov dx, pos
mov ah, 42h
mov al, 2
mov bx, Handle
int 21h
pop dx
pop cx
ENDM
WriteToFile MACRO Handle, strToWrite
mov ah, 40h
mov bx, Handle
mov cx, len
mov dx, offset strToWrite
;lea dx, strToWrite
int 21h
ENDM
ReadFromFile MACRO Handle, strToRead
mov ah, 3Fh
mov bx, Handle
mov dx, offset strToRead
int 21h
ENDM
SetFileAttr MACRO fileName, Attr
mov dx, offset fileName
mov ax, 4300h
int 21h
mov ax, 4301h
add cx, Attr
int 21h
ENDM
RenameFile MACRO oldName, newName
mov ah, 56h
mov dx, offset oldName
mov di, offset newName
int 21h
ENDM
GetDrive MACRO
MOV AH, 19h
INT 21h
ENDM
SetDrive MACRO setDrv
MOV AH, 0Eh
MOV DL, setDrv
INT 21h
ENDM
GetDrive MACRO
MOV AH, 19h
INT 21h
ENDM
SetDrive MACRO setDrv
MOV AH, 0Eh
MOV DL, setDrv
INT 21h
ENDM
MkDir MACRO dirName
MOV AH, 39h
MOV DX, OFFSET dirName
INT 21h
ENDM
RmDir MACRO dirName
MOV AH, 3Ah
MOV DX, OFFSET dirName
INT 21h
ENDM
Problema 4.1. Crearea fisierelor
De realizat programul care în directorul curent creaza un fisier nou cu numele MYFILE.DAT si scrie în el numele si prenumele sau. Daca un asa fisier deja exista datele sa fie înscrise în sfîrsitul fisierului. Dupa executia programului prin comanda DIR de controlat prezenta fisierului în director, iar prin comanda TYPE de imprimat continutul pe ecran.
include macro.lib
.model small
.stack 256
.data
handle dw '?'
fileName db 'OLEG.dat',0
len dw $-fileName
.code
Start:
MOV AX, @DATA
MOV DS, AX
mov ah,3dh
mov al,2
int 21h
je open
mov Handle,ax
cmp ax, 2
je create
jne open
jmp endprog
create:
CreateFile handle, fileName
OpenFile handle, fileName
Seek [handle], 0
WriteToFile [handle], fileName
CloseFile [handle]
open:
OpenFile handle, fileName
Seek [handle], 0
WriteToFile handle, fileName
CloseFile [handle]
endprog:
MOV AH, 4CH
INT 21H
end Start
Problema 4.2. Citirea fisierelor
De realizat programul care îndeplineste citirea continutului fisierului MYFILE.DAT în memoria calculatorului si de imprimat pe ecran. Se presupune ca lungimea fisierului este aleatoare.
include macro.lib
.model small
.stack 256
.data
handle dw '?'
fileName db 'OLEG.dat',0
buffer db 1000 dup('?')
.code
Start:
MOV AX, @DATA
MOV DS, AX
OpenFile handle, fileName
mov cx, 65535
ReadFromFile [handle], buffer
CloseFile [handle]
mov ah, 09h ;pentru a afisa un string la ecran
mov dx, offset buffer
int 21h
MOV AH, 4CH
INT 21H
end Start
Problema 4.3. Acces direct la fisier
De realizat programul ce citeste 8 octeti din fisierul creat anterior MYFILE.DAT începînd c octetul 7, relativ începutului acestuia, 10 octeti din sfîrsitul acestuia si de afisat pe ecran informatia citita.
include macro.lib
.model small
.stack 256
.data
handle dw 0
fileName db 'OLEG.dat',0
buffer db 1000 dup('$')
buff db 1000 dup('$')
.code
Start:
MOV AX, @DATA
MOV DS, AX
OpenFile handle, fileName
mov dx, 7
mov cx, 8
ReadFromFile [handle], buffer
CloseFile [handle]
mov ah, 09h ;pentru a afisa un string la ecran
mov dx, offset buffer
int 21h
OpenFile handle, fileName
mov al, 2
sub dx, 10
mov cx, 10
ReadFromFile [handle], buff
CloseFile [handle]
mov ah, 09h ;pentru a afisa un string la ecran
mov dx, offset buff
int 21h
MOV AH, 4CH
INT 21H
end Start
Problema 4.4. Adaugarea datelor la fisier
De realizat programul ce efectuiaza adaugarea unei linii de text în sfîsitul fisierului de text, mentionat anterior. De controlat continutul si lungimea fisierului pîna si dupa efectuarea operatiei de adaugare (cu ajutorul Norton Commander). De executat din nou programul si de controlat rezultatul.
include macro.lib
.model small
.stack 256
.data
handle dw '?'
fileName db 'OLEG.dat',0
mes db 'Adaugam o linie noua la sfirsitul fisierului',10,13
len equ $-mes
.code
Start:
MOV AX, @DATA
MOV DS, AX
OpenFile handle, fileName
Seek [handle], 0
WriteToFile handle, mes
CloseFile [handle]
MOV AH, 4CH
INT 21H
end Start
Problema 4.5. Modificarea atributelor fisierului
De realizat programul care ataseaza fisierului MYFILE.DAT atributul "numai pentru citire". Dupa executia programului de verificat rezultatul cu ajutorul mijloacelor DOS.
include macro.lib
.model small
.stack 256
.data
handle dw '?'
fileName db 'OLEG.dat',0
.code
Start:
MOV AX, @DATA
MOV DS, AX
mov dx, offset fileName
mov ax, 4300h
int 21h
mov ax, 4301h
mov cx, 01h
int 21h
;SetFileAttr fileName, 00h ;normal
;SetFileAttr fileName, 01h ;numai pentru citire
;SetFileAttr fileName, 02h ;ascuns
;SetFileAttr fileName, 03h ;sistem
;SetFileAttr fileName, 20h ;arhiva
MOV AH, 4CH
INT 21H
end Start
Problema 4.6. Schimbarea numelui fisierului
De realizat programul ce redenumeste fisierul MYFILE.DAT din directorul curent, în NEWNAME.DAT ce se va afla într-un alt director.
include macro.lib
.model small
.stack 256
.data
handle dw '?'
oldName db 'OLEG.dat',0
newName db 'newOLEG.dat',0
;name1 db 'SSSSS.dat',0
.code
Start:
MOV AX, @DATA
MOV DS, AX
MOV ES, AX
mov ah, 56h
mov dx, offset oldName
mov di, offset newName
int 21h
;RenameFile newName, name1
MOV AH, 4CH
INT 21H
end Start
Problema 4.7. Schimbarea discului
De realizat un program ce schimba ca disc curent discul-A si apoi peste o mica întîrziere revine pe discul activ anterior.
.model small
.stack 256
.data
mes1 db 'Discul A',13,10
len2 equ $-mes1
mes2 db 'Discul C',13,10
len1 equ $-mes2
.code
Start:
MOV AX, @DATA
MOV DS, AX
mov ah, 19h ;get Drive
int 21h
mov ah,0Eh ;set Drive
mov dl,0
int 21h
cmp al,0 ;daca A: atunci e bine
je Aactive
jne endprogram
Aactive:
mov ax, 40h
mov bx, 1
mov cx, len1
lea dx, mes1
int 21h
mov ah, 19h ;get Drive
int 21h
mov ah, 0eh
mov dl, 2
int 21h
mov ax, 40h
mov bx, 1
mov cx, len2
mov dx, offset mes2
endprogram:
MOV AH, 4CH
INT 21H
end Start
Problema 4.8. Crearea si stergerea directoarelor
De realizat un program ce creaza la directorul curent subdirectorul NEWDIR si apoi sterge din directorul curent subdirectorul TESTDIR (directorul de regula, nu trebuie sa contina fisiere).
.model small
.stack 256
.data
newDir db 'NewDir',0
new_len dw $-newDir
;new_mes db 'Am creat directoriul NewDir',10,13
;new_mes_len equ $-new_mes
testDir db 'NewDir\TestDir',0
test_len equ $-testDir
.code
Start:
MOV AX, @DATA
MOV DS, AX
;mov ax, 40h
;mov bx, 1
;mov cx, new_mes_len
;lea dx, new_mes
;int 21h
mov ah, 39h ;cream directoriul NewDir
mov dx, offset newDir
int 21h
mov ah, 39h ;cream directoriul TestDir
mov dx, offset testDir
int 21h
mov ah, 3ah ;distrugem directoriul TestDir
mov dx, offset testDir
int 21h
MOV AH, 4CH
INT 21H
end Start
Concluzie:
Noi în aceasta lucrare de laborator am studiat sistemul de intreruperi a sistemului de gestiune a fisierelor, al sistemului de operare MS-DOS. Am creat fisiere noi, le-am redenumit, le-am schimbat atributele lor, am lucrat cu unitatile de discuri, am creat directoare noi dintre care am sters unul din ele.
|