CSEG segment assume CS CSEG DS CSEG ES CSEG SS CSEG org 100h _start mo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CSEG segment
assume CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
org 100h
_start:
mov ax, 3D00h ; open (read only)
mov dx, offset File
int 21h
jc _open_err
mov Handler, ax ; ax = file address in memory
mov bx, ax ; copy file handler to bx
mov cx, 0FDE8h ; read 65000 bytes
mov dx, offset Buffer
mov ah, 3Fh ; read file function
int 21h
mov ah, 3Eh ; close file
int 21h
jmp _success_read
_success_read:
mov ah, 9
mov dx, offset Success_read
int 21h
jmp _exit
_open_err:
mov ah, 9
mov dx, offset Error_open
int 21h
jmp _exit
_exit:
mov dx, offset Getch
mov ah, 9
int 21h
mov ah, 10h
int 16h
int 20h
File DB 'readfile.asm', 0
Error_open DB 'Cannot open file!$'
Success_read DB 'File read successfully!$'
Getch DB 0Dh, 0Ah, 'Please press any key for exit...$'
Handler DW 0 ; file handler
Buffer equ $ ; buffer for read file
CSEG ends
end _start