I’ve been working a program in x86 assembly for MSDOS, that opens a file and displays it’s contents..however, i’m stumped on the reading the file part..
Basically, i dynamically allocated filesize amount of bytes using INT 21h, 48h , and i want the program to write the file’s contents into the allocated space…however, the memory address that’s returned by the interrupt is a segment address, and the interrupt responsible for reading the file’s contents exclusively requires it to be inside DS.
.MODEL SMALL
.STACK 100h
READ equ 0
SEEK_END equ 2
.DATA
file_name db "test.txt",0
file_handle dw ?
file_size dw ?
file_segment dw ?
.CODE
main PROC
mov ax, @DATA
mov ds, ax
;Return the file's handle.
mov ah, 3Dh
mov al, READ
lea dx, file_name
int 21h
mov [file_handle], ax
mov bx, ax
;Get the file's size by going to the end of the file and retrieving new the pointer location.
mov ah, 42h
mov al, SEEK_END
xor dx, dx
int 21h
mov [file_size], ax
;Calculate the amount of paragraphs necessary for the allocation (1 paragraph = 16 bytes).
add ax, 15
mov cl, 4
shr ax, cl
;Allocate the memory.
mov bx, ax
mov ah, 48h
int 21h
mov [file_segment], ax
;Write the file's contents into memory.
mov ah, 3Fh
mov bx, [file_handle]
mov cx, [file_size]
;DX is supposed to be the pointer offseted by DS.
int 21h
;Terminate Program.
mov ah, 4Ch
int 21h
main ENDP
END main
FYI, i ran Turbo Debugger and there doesn’t seem to any problem with the program, it’s just the reading file that doesn’t work…
This is the website i got my interrupt information from by the way : https://www.stanislavs.org/helppc/int_21.html
I wanted the program to write into the dynamically allocated block of memory, so i tried changing the DS register’s address inside the interrupt, i tried using ASSUME, i tried scouring throught the deepest depths of the Google results, i got so low i asked ChatGPT for help, yet none of it worked..