EASy68K  
It is currently Mon Jul 24, 2017 8:47 pm

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Detecting End-Of-File
PostPosted: Wed Nov 08, 2006 7:30 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1040
I received an email asking for an example on how to detect the End-Of-File when doing file I/O.

This example assumes a text file named test1.txt exists in the same directory as the example.

Code:
*-----------------------------------------------------------
* Program Number:
* Written by    : Chuck Kelly
* Date Created  : November-8-2006
* Description   : Demonstrate file I/O in EASy68K
*                 Reads and displays the contents of "test1.txt" file.
*                 Loops until End-Of-File is reached.
*-----------------------------------------------------------
  ORG   $800
  lea   filename,a1
  move   #51,d0         ;open "test1.txt" file
  trap   #15         ;returns file ID in d1
  move.l d1,d4         ;save file ID

  * Read lines from file and display
  * Loop until EOF reached
  lea   buffer,a1
  clr   d2
  repeat
    if.b d2 <ne> #0 then.s   ;if data was read from file
      move.l   d2,d1      ;number of characters read
      move   #1,d0      ;display text at (A1)
      trap   #15
    endi
    move.l   d4,d1      ;restore file ID
    move   #80,d2      ;# bytes to read
    move   #53,d0      ;read from file
    trap   #15
  until.w d0 <eq> #1 do.s   ;until EOF

  move   #50,d0
  trap   #15         ;close all files

  STOP   #$2000

filename dc.b   'test1.txt',0
buffer    ds.b   80

   END   $800

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group