how could i read a text(character by character) from a file then store it in an array,using assembly(TASM only) for 8086 processor

Which is the problem?
- reading the file
- storing it in an array
- storing it in an array which is big enough

Show us your progress first, then we help (see the announcements)

hello
below the procedure of reading from text file using 8086 microprocessor and tasm and storing the text in array called array.
note that data_file is a db variable contains the name of the file with its directory,, |c:\tasm\file_name|,,
//
proc read_file
PUSHA
MOV AH, 3DH ;Open the file
MOV AL, 0 ;Open for reading
LEA DX, data_file ;Presume DS points at filename
INT 21H ; segment
JC BADOPEN
MOV HANDLE, AX ;Save file handle
XOR SI, SI
LP:
MOV AH , 3FH ;Read data from the file
LEA DX, array[SI] ;Address of data buffer
MOV CX, 40 ;Read 256 bytes
MOV BX, HANDLE ;Get file handle value
INT 21H
JC BADOPEN

INC MY_SIZE
ADD SI , 40
MOV BX , AX
MOV CX , AX
JCXZ EOF

MOV AH , 3FH ;Read data from the file
LEA DX, LOCATION ;Address of data buffer
MOV CX, 1 ;Read 256 bytes
MOV BX, HANDLE ;Get file handle value
INT 21H
; seek:
MOV DI , AX
MOV AH, 42H
MOV BX, HANDLE
MOV AL, 0
MOV CX, 0
MOV DX, SI
INT 21H

CMP LOCATION , '0'
JE EOF
JMP LP ;Read next block

EOF:
MOV BX, HANDLE
MOV AH, 3EH ;CLOSE FILE
INT 21H
JMP ENDOS


BADOPEN:

mov ah,02h
mov bh,08
mov dh,11H
mov dl,cl
int 10h

LEA DX , ERRORS
mov ah , 09
int 21h
jmp exit
ENDOS :

POPA

RET
READ_FILE ENDP
\\
hope to be th answer of your quastion

How would you read the size of an input file (like input.txt) and have the program dynamically determine how long it is without allocating a certain amount of space for it. More specifically, I'm trying to read the contents of two input files and have one perform mathematical operations on the other file. Then, to write the output, the program would have to know how long the input file was so it knows how many times to loop to write to the output file. All of the files are planned to be in quad word format.

Thanks

Edited 5 Years Ago by guyfromnola: mistype

This article has been dead for over six months. Start a new discussion instead.