WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

Reading from a file, I need to read 16 characters (one per line) and store them in the array, then wait for the user to press A.

smokymo
Quote Post


New Member
*

Group: Members
Posts: 6
Member No.: 15211
Joined: 17-November 08


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)

CODE
.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.

Sponsored Links
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2311
Member No.: 160
Joined: 22-June 04


what exactly you wish to get as help?
you have to not close file until end of program, or move file pointer each time to the next position. currently code reads each time first 46 ( :o ) bytes - maybe because of strict <char><0d><0a>*16-2=46 txt file structure.
if you have trouble to compile it from winasm studio - here is the ready project as is. you have to have TASM environment var set in system or studio environment and tasm.exe must be found at %TASM%\BIN folder (or change compilation lines by yourself, read FASM add-in documentation for more)

regards!

Attached File ( Number of downloads: 36 )
 Login or Register to download
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google