CS344-321 Assembly Language Programming

Download Report

Transcript CS344-321 Assembly Language Programming

CS344-321 Assembly
Language Programming
Period 35
่
การใช้ทร ัพยากรของเครือง
DOS FILE SYSTEM
มี file handle 5 อ ันที่ automatic open และไม่ตอ
้ ง close คือ
Handle
Use
Default Setting
(file name)
0
Standard input (keyboard)
CON
1
Standard output (screen)
CON
2
Standard error (screen)
CON
3
Standard auxiliary
AUX
4
Standard printer (LPT1: or PRN)PRN
Function
Parameters
Results
Int 21h function 3ch
AH = 3ch
If
function successful
Create file
CX = file attribute
CF =
0
DS:DX=address of ASCIIZ filename
AX =
handle
if function unsuccessful
CF = 1
AX = error code
Int 21h function 3dh
AH = 3dh
If
function successful
Open file
AL = access mode
CF =
0
DS:DX=address of ASCIIZ filename
AX =
handle
if function unsuccessful
Int 21h function 3fh
AH = 3fh
function successful
Read file
BX = handle
CX = number of bytes
transferred
DS:DX=buffer address
unsuccessful
Int 21h function 40h
AH = 40h
function successful
Write file
BX = handle
CX = number of bytes
transferred
DS:DX=buffer address
unsuccessful
If
CF = 0
AX = bytes
if function
CF = 1
AX = error code
If
CF = 0
AX = bytes
if function
CF = 1
Int 21h function 42h
AH = 42h
If
function successful
Set file pointer
AL = method (0=relative to start
CF = 0
of file, 1=relative to current
DX:AX = actual file offset
file position, 2 = relative to
if
function unsuccessful
end of file)
CF
=1
BX = handle
AX = error code
CX:DX=
offset value
Int 21h function 3eh
AH = 3eh
function successful
Close file
BX = handle
unsuccessful
If
if function
CF = 0
Int 21h function 41h
AH = 3eh
If
function successful
Delete file
DS:DX = address of ASCIIZ filename
CF = 0
if function unsuccessful
CF = 1
AX = error code
Int 21h function 56h
AH = 56h
function successful
Rename file DS:DX = address of ASCIIZ current
0
filename
unsuccessful
ES:DI = address of ASCIIZ new
filename
error code
If
CF =
if function
CF = 1
AX =
่ นสุ
้ ดด้วย 0 เช่น file_name
-หมายเหตุ ASCIIZ คือ string ทีสิ
db ‘test.dat’,0
-file attribute
bit
value(hex)
meaning
76543210
00000000
0
normal
00000001 1
Read-only
00000010
2
Hidden
00000100
4
System
00001000
8
Volume label
00010000
10
Subdirectory
00100000
20
Archive
01000000
40
Unused
10000000
80
Unused
-access mode
20h
Read (only) access
40h
Read or write access
่ อยู ่แล้ว ต้อง open ก่อนถึงจะใช้ได้ และเมือเลิ
่ กใช้ตอ
-file ทีมี
้ ง
close เสมอ
-ข้อควรระมัดระวัง ! กรณี ทสร
ี่ ้าง file ใหม่ โดยใช้ฟังก ์ช ัน
้
้
Create file ถ้าปรากฏว่ามี file นันอยู
่แล้ว ข้อมู ลใน file นันจะ
่ งั กล่าวอยู ่
หาย ข้อแนะนาควรทดสองตรวจสอบดู วา
่ มี file ชือด
่
หรือไม่ ด้วยฟั งก ์ช ัน open file ถ้าไม่ม ี error แสดงว่ามี file ชือ
้
่ งั กล่าวหรือไม่
นันอยู
่ ควรถาม user ว่าต้องการสร ้าง file ชือด
เพราะข้อมู ลเดิมจะหาย (File exist, replace[y/n]?) ถ้า user
ตอบ y จึงใช้ฟังก ์ช ัน Create file