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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
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.
MS DOS File IO Text chapter 13. DateTime C:\MASM615>make16 datetime Assembling: datetime.asm Volume in drive C has no label. Volume Serial Number is 07D
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address.
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.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Assembly Language for Intel-Based Computers Chapter 13: 16-Bit MS-DOS Programming Kip R. Irvine.
Kip Irvine: Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved. You may.
Structure of DOS application programs. Contents: 1. PSP 2..COM and.EXE 3. TSR: Terminate and Stay Resident Programs.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
CE302 Outline Multiplication Division Program Segment Prefix Command Line Parameters.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 13: 16-Bit MS-DOS Programming (c) Pearson Education, All rights reserved.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Assembly Language for x86 Processors 6th Edition
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.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
1 Screen and Keyboard Operations Suthida Chaichomchuen
Runtime Program Structure Command.com program supplied with MS- DOS and Windows (CMD.EXE for 2000 and XP)is called the command processor. It interprets.
Assembly Language for Intel-Based Computers Chapter 13: 16-Bit MS-DOS Programming Kip R. Irvine.
C++ for Engineers and Scientists Second Edition Chapter 8 I/O File Streams and Data Files.
CET 3510 Microcomputer Systems Tech. Lecture 2 Professor: Dr. José M. Reyes Álamo.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
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.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.
Writing and Reading Files Methods for processing disk files File Control Blocks (FCBs) –Supported by DOS –Can address drives and filenames.
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:
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.
Chapter Bit MS-DOS Programming Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
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.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
Programming with ANSI C ++
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Chapter 7 Text Input/Output Objectives
Microprocessor and Assembly Language
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Symbolic Instruction and Addressing
Unit:08 Software Interrupts
Process.
Presentation transcript:

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 to identify files and I/O devices.

5 Predefined Device Handles 0 – keyboard (standard input) 1 – console (standard output) 2 – Error Output 3 – Auxiliary Device (Async) 4 - Printer

Errors If one of the I/O functions fail, the carry flag is set, and an error code is returned in AX. You can use this error code to display an appropriate error message. Table 13-4 (pg ) lists error codes.

File I/O Services (3Ch) Create File (3Dh) Open File (3Eh) Close File (3Fh) Read from File or Device (40h) Write to File or Device (42h) Move file pointer (716Ch) Extended Mode file creation or open

3Dh Open File Three File Modes (Stored in AL) –0 – Input (Read Only) –1 – Output (Write Only) –2 – Input/Output Error Codes (CF=1, AX holds codes) –1 – Invalid Function Number –2 – File Not Found –3 - Path Not Found –4 – Too Many open files –5 - Access Denied

Open File (if carry, error; if no error, ax = filename).data filenamedb‘A:\FILE1.DOC’,0 infilehandledw?.code movah, 3Dh;function: open file moval,0;choose the input mode movdx, offset filename int21h;call DOS jcdisplay_error;error? Display a message movinfilehandle, ax;no error: save the handle

(3Eh) Close File Only 1 possible error code –6 – Invalid handle.data filenamedb‘A:\FILE1.DOC’,0 infilehandledw?.code mov ah, 3Eh;function: close file handle movbx, infilehandle int21h;call DOS jcdisplay_error;error? Display a message

Close File.data filenamedb‘A:\FILE1.DOC’,0 infilehandledw?.code mov ah, 3Eh;function: close file handle movbx, infilehandle int21h;call DOS jcdisplay_error;error? Display a message

(3Fh) Read From File or Device Can read from keyboard or disk file First use 3D to open file, then use 3F to read Errors (CF=1) –5 – Access Denied –6 – invalid handle If CF=0, AX contains # of bytes read Useful for echecking for EOF

Read from File.data bufferSize = 512 filehandledw? bufferdbbufferSize dup(0).code mov ah, 3Fh;read from file or device movbx, filehandle;BX = file handle movcx, buffersize;number of bytes to read movdx, offset buffer;point to buffer int21h;read the data jcdisplay_error;error if CX=1 cmpax, cx;cmp to bytes requested jbeExit;yes? Quit reading

(42h) Move File Pointer AL = Method –0 – Offset from beginning of file –1 – Offset from current location –2 – Offset from end of file CX:DX holds offset BX holds filehandle Errors (CF=1) –1 – invalid function number –6 – Invalid Handle After sucessful operation, CF=0, DS:AX= location of file pointer offset from beginning of file

Move File Pointer/Collect Data.code mov ah, 42h;function: move pointer moval,1;method: movbx, filehandle;BX = file handle movcx, 0 movdx, -10;offset can be negative int21h jcdisplay_error;error if CX=1 mov3Fh;function: read file movcx, 10;read 10 bytes movdx, inbuf int21h

Reading the MS_DOS Command Tail When a program runs, any additional text on the command line is automatically stored in the 128-byte command tail area Command Tail found at offset 80h in the PSP (256-byte block at beginning of code) The first byte contains the number of characters typed on the command line. In Codeview- choose runtime arguments from the run menu No arguments saved in redirection of I/O.

Get_Commandtail Procedure From Irvine link library Returns a copy of the command tail (DX should point to offset of buffer where command tail is to be copied) Skips over leading spaces Sets carry flag if empty

Creating Binary Files Binfile.asm Binary files – data is a binary image of the program data. If file has binary data in it, you would have to convert each integer to a string and write it separately. Create a program that creates and fills an array with 50 doublewords. (200 bytes) Binfile fills an array with random integers, displays the integers on the screen, writes the integers to a binary file, and closes the file. It then reopens the file, reads the integers, and displays them.