Writing and Reading Files Methods for processing disk files File Control Blocks (FCBs) –Supported by DOS –Can address drives and filenames.

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Chapter 4 : File Systems What is a file system?
Real-Mode Interrupts Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Writing and reading files. Creating a file on a disk Get a file handle from system Use INT 21H function 3C to create a directory entry for the file Use.
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Flow Diagram: Push flags, CS, IP Pop IP,CS,flags Push AX,BX,CX,DX,ES,DS,SI,DI,BP POP BP,DI,SI,DS,ES,DX,CX,BX,AX.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
8.7 Memory management Program E Program D System memory DOS INT 21, function 48H: Allocate Memory Specification: allocates a number of memory paragraphs.
Chapter 9 Using Disks and Files Objectives: The difference between Floppy and Hard Disks What the Boot Sector is for What the File Allocation Table is.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
ECE291 Computer Engineering II Lecture 13 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
1 Screen and Keyboard Operations Suthida Chaichomchuen
1 Microprocessor-based Systems Course 8 Design of input/output interfaces.
Multiplication and Division Instructions & the 0Ah function.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Debuggers A program needed when writing any type of code Displays the contents of memory Lets you view registers and variables and see how they change.
File I/O MS-DOS Interrupt 21h has many functions dealing with file and directory I/O services. Both MS-DOS and MS_Windows use 16- bit integers called HANDLES.
Offset Length Description 0 2 An INT 20h instruction is stored here 2 2 Program ending address 4 1 Unused, reserved by DOS 5 5 Call to DOS function.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
CE Operating Systems Lecture 17 File systems – interface and implementation.
A Technical and Historical look at MS-DOS CS-460 Fall 2003 Authors: Jimmy Conaway, Matt Carey, Itri Idsalah.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
File Systems cs550 Operating Systems David Monismith.
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt.
Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming Interrupts (c) Pearson Education, All rights reserved.
Learners Support Publications Working with Files.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
Preliminary to Assembly Language Programming CE 140 A1/A2 28 June 2003.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Format of Assembly language
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Microprocessor and Assembly Language
Introduction to 8086 Microprocessor
8086 Microprocessor.
A “Walk Through” Experiment
Microprocessor and Assembly Language
ADDRESSING MODES.
CS-401 Computer Architecture Assembly Language Programming
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
CS-401 Computer Architecture & Assembly Language Programming
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Handles disk file 0000: array of file-offsets 0001: 0002: 0003: 0: …
CS-401 Computer Architecture & Assembly Language Programming
Symbolic Instruction and Addressing
Unit:08 Software Interrupts
Disk Structure Analysis
Chapter 6 –Symbolic Instruction and Addressing
By Nasser Halasa Assembly Language.
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Presentation transcript:

Writing and Reading Files

Methods for processing disk files File Control Blocks (FCBs) –Supported by DOS –Can address drives and filenames –Cannot address directories File Handles –Accessing of the file –Return codes to identity errors

Operations using File Handles Use INT 21H services –3CH : Create file –3DH : Open file –3EH : Close file –3FH : Read record –40H : Write record –42H : Move file pointer

Operations using File Handles Use other services –INT 25H : Absolute read –INT 26H : Absolute write

Operations using FCBs Use INT 21H services –0FH : Open file –10H : Close file –14H : Read record –15H : Write record –16H : Create file –21H : Read record randomly –22H : Write record randomly –27H : Read block randomly –28H : Write block randomly

ASCIIZ strings Containing the filespec : –the location of the disk drive –directory path –filename –‘All optional within apostrophes’ –a bytes of hex zeros –maximum length string is 128 bytes

ASCIIZ strings Example1 : defines a drive and filename –PATHNAM1 DB ‘D:\Filetest.asm’, 00H Example2 : defines a drive, subdirectory and filename –PATHNAM2 DB ‘E:\Utility\Filetest.exe’, 00H

File Handles Standard devices –00 = input –01 = output –02 = error output –03 = auxiliary device –04 = printer

Error Return Codes File handle operations for disk deliver a “completion status” via –Carry flag –Register AX Successful operation –clear carry flag & perform other functions Unsuccessful operation –set carry flag & return an error code in AX

Lists of error codes : : Invalid function number 02 : File not found 03 : Path not found 04 : Too many file open 05 : access denied 06 : Invalid handle 07 : Memory control block destroyed 08 : Insufficient memory 09 : Invalid memory block address 10 : Invalid environment

Lists of error codes : : Invalid format 12 : Invalid access code 13 : Invalid data 15 : Invalid drive specified 16 : Attempt to remove directory 17 : Not same device 18 : No more files 19 : Write-protected disk 20 : Unknown unit

Lists of error codes : : Invalid function number 22 : Unknown command 23 : CRC data error 24 : Bad request structure length 25 : Seek error 26 : Unknown media type 27 : Sector not found 28 : Printer out of paper 29 : Write fault 30 : Read fault

Lists of error codes : : General failure 32 : Sharing violation 33 : Lock violation 34 : Invalid disk change 35 : FCB unavailable 36 : Sharing buffer overflow

File Pointers ตัวชี้ที่ทำหน้าที่ชี้ตำแหน่งข้อมูลของไฟล์ เมื่อเปิดไฟล์ Pointer จะชี้ที่ไบท์แรกเสมอ การเคลื่อนย้ายข้อมูลในไฟล์ต้องย้าย file pointer ไปยังตำแหน่งที่ต้องการ โดยใช้ INT 21H function 42H

Using File handles to create disk files Procedure for writing a disk –Use an ASCIIZ string to get a file handle from the system –Use INT 21H function 3CH to create the file –Use INT 21H function 40H to write records in the file –Use INT 21H function 3EH to close the file

INT 21H Function 3CH : Create File AH = 3CH CX = File attribute DX = Address of the ASCII string

INT 21H Function 3CH : Create File File attribute –00H : Normal file –01H : Read only –02H : Hidden file –04H : System file –08H : Volume label –10H : Subdirectory –20H : Archive file

INT 21H Function 3CH : Create File Example –PATHNAM1DB‘E:\ACCOUNTS.FIL’, 00H –FILHAND1DW? –... – MOVAH,3CH – MOVCX,00 – LEADX,PATHNAM1 – INT21H – JCerror – MOVFILHAND1,AX

INT 21H Function 40H : Write Record AH = 40H BX = Stored file handle CX = Number of bytes to write DS:DX = Address of the output area

Example –FILHAND1DW? –OUTAREADB256 DUP(‘ ‘) –... – MOVAH,40H – MOVBX,FILHAND1 – MOVCX,256 – LEADX,OUTAREA – INT21H – JCerror2 – CMPAX,256 – JNEerror3 INT 21H Function 40H : Write Record

INT 21H Function 3EH : Close File AH = 3EH BX = File handle

Example –MOVAH,3EH – MOVBX,FILHAND1 – INT21H INT 21H Function 3EH : Close File

Using File handles to read disk files Procedure for reading a disk file –Use an ASCIIZ string to get a file handle from the system –Use INT 21H function 3DH to open the file –Use INT 21H function 3FH to read records from the file –Use INT 21H function 3EH to close the file

INT 21H Function 3DH : Open File AH = 3DH AL = Access code –00 : Read only –01 : Write only –02 : Read/Write DX = Address of the ASCII string

Example –FILHAND2DW? –... – MOVAH,3DH – MOVAL,00 – LEADX,PATHNAM1 – INT21H – JCerror4 – MOVFILHAND2,AX INT 21H Function 3DH : Open File

INT 21H Function 3FH : Read Record AH = 3FH BX = File handle CX = Number of bytes to read DS:DX = Address of the input area

Example –FILHAND2DW? –INAREADB512 DUP(‘ ‘) –... – MOVAH,3FH – MOVBX,FILHAND2 – MOVCX,512 – LEADX,INAREA – INT21H – JCerror5 – CMPAX,00 – JEendfile INT 21H Function 3FH : Read Record

INT 21H Function 42H : Move File Pointer AH = 42H BX = File handle CX : DX = Offset address required AL = Method code –00 : Take the offset from the start of the file –01 : Take the offset from the current location of the file pointer –02 : Take the offset from the end-of-file

Example –MOVAH,42H – MOVAL,00 – MOVBX,HANDLE1 – MOVCX,00 – MOVDX,1024 – INT21H – JCerror INT 21H Function 42H : Move File Pointer