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