smokymo
December 3rd, 2008, 09:59 AM
I need to read a 16 characters(one per line) and store them in the array, than wait for a user to press "A" and read another 16 characters.(this is not my code and I am tring to modify it)
.model small
.stack
.data
Handle DW ? ;to store file handle
FileName DB "f:\ca225\text.txt",0 ;file to be opened
OpenError DB "An error has occured(opening)!$"
ReadError DB "An error has occured(reading)!$"
array db 46(?)
Buffer DB 16 dup (?) ;buffer to store data
.code
start:
mov ax,@data ;base address of data segment
mov ds,ax ;put this in ds
re:
mov dx,OFFSET FileName ;put address of filename in dx
mov al,0 ;access mode - read and write
mov ah,3Dh ;function 3Dh -open a file
int 21h ;call DOS service
mov Handle,ax ;save file handle for later
jc ErrorOpening ;jump if carry flag set - error!
mov dx,offset Buffer ;address of buffer in dx
mov bx,Handle ;handle in bx
mov cx,46 ;amount of bytes to be read
mov ah,3Fh ;function 3Fh - read from file
int 21h ;call dos service
jc ErrorReading ;jump if carry flag set - error!
mov bx,Handle ;put file handle in bx
mov ah,3Eh ;function 3Eh - close a file
int 21h ;call DOS service
mov cx,46 ;length of string
mov si,OFFSET Buffer ;DS:SI - address of string
xor bh,bh ;video page - 0
mov ah,0Eh ;function 0Eh - write character
sub si,si
NextChar:
lodsb ;AL = next character in string
mov [array+si],al
inc si
loop NextChar
;xor ah,ah ;function 00h - get character
;int 16h ;interrupt 16h
;cmp al,041h
;je re
mov ax,4C00h ;terminate program
int 21h
ErrorOpening:
mov dx,offset OpenError ;display an error
mov ah,09h ;using function 09h
int 21h ;call DOS service
mov ax,4C01h ;end program with an errorlevel =1
int 21h
ErrorReading:
mov dx,offset ReadError ;display an error
mov ah,09h ;using function 09h
int 21h ;call DOS service
mov ax,4C02h ;end program with an errorlevel =2
int 21h
END start
the text file will look like this but with more characters
1
_
3
4
5
2
B
8
D
9
6
C
E
A
F
7
I am using tasm,x86.
.model small
.stack
.data
Handle DW ? ;to store file handle
FileName DB "f:\ca225\text.txt",0 ;file to be opened
OpenError DB "An error has occured(opening)!$"
ReadError DB "An error has occured(reading)!$"
array db 46(?)
Buffer DB 16 dup (?) ;buffer to store data
.code
start:
mov ax,@data ;base address of data segment
mov ds,ax ;put this in ds
re:
mov dx,OFFSET FileName ;put address of filename in dx
mov al,0 ;access mode - read and write
mov ah,3Dh ;function 3Dh -open a file
int 21h ;call DOS service
mov Handle,ax ;save file handle for later
jc ErrorOpening ;jump if carry flag set - error!
mov dx,offset Buffer ;address of buffer in dx
mov bx,Handle ;handle in bx
mov cx,46 ;amount of bytes to be read
mov ah,3Fh ;function 3Fh - read from file
int 21h ;call dos service
jc ErrorReading ;jump if carry flag set - error!
mov bx,Handle ;put file handle in bx
mov ah,3Eh ;function 3Eh - close a file
int 21h ;call DOS service
mov cx,46 ;length of string
mov si,OFFSET Buffer ;DS:SI - address of string
xor bh,bh ;video page - 0
mov ah,0Eh ;function 0Eh - write character
sub si,si
NextChar:
lodsb ;AL = next character in string
mov [array+si],al
inc si
loop NextChar
;xor ah,ah ;function 00h - get character
;int 16h ;interrupt 16h
;cmp al,041h
;je re
mov ax,4C00h ;terminate program
int 21h
ErrorOpening:
mov dx,offset OpenError ;display an error
mov ah,09h ;using function 09h
int 21h ;call DOS service
mov ax,4C01h ;end program with an errorlevel =1
int 21h
ErrorReading:
mov dx,offset ReadError ;display an error
mov ah,09h ;using function 09h
int 21h ;call DOS service
mov ax,4C02h ;end program with an errorlevel =2
int 21h
END start
the text file will look like this but with more characters
1
_
3
4
5
2
B
8
D
9
6
C
E
A
F
7
I am using tasm,x86.