Hello everyone,
My goal is to take a file, 400 characters in length, 1 per line, and read it into my assembly program. Each character is a number which I would like to use later to draw a 20x20 picture so to speak.
How do I read the numbers into the program using int 21h for 16-bit and Irvine functions for 32-bit?
So far for 16-bit I have the following code...
The file it is reading from goes like this...
Why is the second writedec printing out a 13 instead of a 50? Shouldn't it be the same decimal number for the ascii character 2?
How do I move onto the next number in the code and then read it?
Thanks in advance...
-Mallard
My goal is to take a file, 400 characters in length, 1 per line, and read it into my assembly program. Each character is a number which I would like to use later to draw a 20x20 picture so to speak.
How do I read the numbers into the program using int 21h for 16-bit and Irvine functions for 32-bit?
So far for 16-bit I have the following code...
TITLE First 16-bit Program (main.asm)
; Description:
;
; Revision date:
INCLUDE Irvine16.inc
.data
infile BYTE "pix.txt",0
infp WORD ?
bef BYTE 0
str1 BYTE 10 dup('$')
aft BYTE 0
arr BYTE 400 dup(0)
x BYTE 0
y WORD 0
num BYTE 0
.code
main PROC
mov ax,@data
mov ds,ax ;these two lines required for 16-bit programs
;; open an input file for reading
mov ah,3dh
mov al,0
mov dx,offset infile
int 21h
jc quit
mov infp,ax
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
mov al,num
call writedec
call crlf
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
mov al,num
call writedec
call crlf
;close the file
mov ah,3eh
mov bx,infp
int 21h
jc quit
quit:
mov ah,2
mov dl,'-'
;int 21h
call crlf
mov ah,4ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
The file it is reading from goes like this...
2
2
2
2
2
Why is the second writedec printing out a 13 instead of a 50? Shouldn't it be the same decimal number for the ascii character 2?
How do I move onto the next number in the code and then read it?
Thanks in advance...
-Mallard
because you are reading only 2 bytes in the file... the first byte is the number 2, the second byte you are getting is correct - 13 which is carrage return and the third byte would probably be 10 for line feed.
If you use the 32 bit Irvine library, then there is a function - ReadFile that will read the file into a buffer. then you just loop through the file. As for using interrupts, dunno a little outdated so don't use em. You would read a byte, increase a counter for the pos then read another byte, skipping the CR and LF 13, 10. Or you can use the MASM32 library function called ltok which will tokenize a buffer and each number will be parsed out for you to loop through the array
If you use the 32 bit Irvine library, then there is a function - ReadFile that will read the file into a buffer. then you just loop through the file. As for using interrupts, dunno a little outdated so don't use em. You would read a byte, increase a counter for the pos then read another byte, skipping the CR and LF 13, 10. Or you can use the MASM32 library function called ltok which will tokenize a buffer and each number will be parsed out for you to loop through the array
So essentailly everytime I want a number I have to move that offset 2 times. This will put me past CR and LF.