Skip to content

Instantly share code, notes, and snippets.

@iamdylanngo
Last active May 3, 2022 09:21
Show Gist options
  • Save iamdylanngo/7924559df9e5a5f5677a0413bf61aec2 to your computer and use it in GitHub Desktop.
Save iamdylanngo/7924559df9e5a5f5677a0413bf61aec2 to your computer and use it in GitHub Desktop.
io-file-read
.model small
.data
Filename db 'file.txt',00h
FHndl dw ?
Buffer db 80h dup(?)
.stack 100h
.code
Program:
mov ax, @data
mov ds, ax
mov ah, 3dh ;Open the file
mov al, 0 ;Open for reading
lea dx, Filename ;Presume DS points at filename
int 21h ; segment.
; jc BadOpen
mov FHndl, ax ;Save file handle
LP: mov ah,3fh ;Read data from the file
lea dx, Buffer ;Address of data buffer
mov cx, 1 ;Read one byte
mov bx, FHndl ;Get file handle value
int 21h
; jc ReadError
cmp ax, cx ;EOF reached?
jne EOF
mov al, Buffer ;Get character read
call write ;Print it
jmp LP ;Read next byte
EOF: mov bx, FHndl
mov ah, 3eh ;Close file
int 21h
;jc CloseError
write PROC
push ax bx cx dx
mov ah, 2
mov dl, Buffer ;char to be printed
int 21h
pop ax bx cx dx
ret
ENDP
End Program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment