Author Topic: Need More Example Code  (Read 1853 times)

fritzgamaliel

  • Regular Member
  • *
  • Posts: 1
Need More Example Code
« on: July 25, 2015, 10:21:14 PM »
Hello,

This is my first post.

I already searched for the following two topics in search engine
and another assembly language forum:
Topic 1 -> int 13h
Topic 2 -> int 17h

But I did not find what I wanted.

I wanted to create, write, and read file using int 13h.
And I wanted to print out some data into my USB printer using int 17h.

 :(

FORTRANS

  • Member
  • ****
  • Posts: 945
Re: Need More Example Code
« Reply #1 on: July 25, 2015, 11:17:57 PM »
Hi,

   Well, Interrupt 17H seems simple enough..

INT 17      Printer Services

   Provides functions to use the printer or parallel port

INPUT  AH = 0 = Print Character in AL
       AH = 1 = Initialize Printer
       AH = 2 = Get Printer Status


   Interrupt 13H has a lot of functions.  Int 13H AH = 2, reads
sectors from the disk .  The reference I have says, AL = number of
sectors to read, CH = low eight bits of the cylinder number, CL bits
6 & 7 are cylinder number bits 8 & 9, CL bits 0 - 5 are the starting
sector number.  DH is the starting head number.  DL is the disk number,
80H is the first hard disk.  0 will be the first diskette drive.  ES:BX
pointer to buffer to receive data.  Carry = 0, successful, carry = 1,
error.  And so forth.

   Int 13H AH = 3 is write disk sectors.  But it does not know of a
file system.  Disk sectors are different from a file on a disk.

   So I would suggest using MS-DOS Interrupt 21H file functions
instead.  Then you can specify a file by name, and then read from,
write to, or create the file as needed.  Much, much easier.  And you
can open the PRN: device as a file and write to it to access the printer.

  Ralf Brown' Interrupt List (RBIL) is a web reference if you still want
to use Int 13H.  I am using "The Undocumented PC", which was the
printed version, older but easier to use.

   Or, as this forum is for MASM32, you could try the Windows API,
and get more help from more members here.

HTH,

Steve N.

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Need More Example Code
« Reply #2 on: July 26, 2015, 12:34:49 AM »
Hi fritzgamaliel,

first things first: Welcome to the forum.

Here is a link to Ralph Browns interrupt list. I hope that helps.

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Need More Example Code
« Reply #3 on: July 27, 2015, 02:39:07 AM »
i am a little surprised noone told you to avoid 16-bit code - lol

unless there is some reason (like the instructor is stuck in the past), use 32-bit code

as Steve mentioned, use INT 21h for file i/o
not even sure how well INT 13h would work with NTFS drives - lol
if you're reading and writing on a floppy, it might be ok

in INT 21h, there are 2 "modes" that may be used to access files
one mode uses the FCB's - avoid those functions, it's just extra headache

these are the functions you'll use the most:

INT 21h, AH=3Ch create file
INT 21h, AH=3Dh open existing file
INT 21h, AH=3Eh close file handle
INT 21h, AH=3Fh read file
INT 21h, AH=40h write file
INT 21h, AH=41h delete file
INT 21h, AH=42h set file pointer
INT 21h, AH=43h get or set file attributes

also, for working with directories...

INT 21h, AH=39h create directory
INT 21h, AH=3Ah remove directory
INT 21h, AH=3Bh change current directory
INT 21h, AH=47h get current directory

also of interest....

INT 21h, AH=4Eh find first file
INT 21h, AH=4Fh find next file

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Need More Example Code
« Reply #4 on: July 28, 2015, 01:32:12 AM »
in INT 21h, there are 2 "modes" that may be used to access files
one mode uses the FCB's - avoid those functions, it's just extra headache

yes, of course. The FCB based functions are for compatibility reasons with CP/M. One should use the handle based functions. That's a general rule of thumb.

Gunther
Get your facts first, and then you can distort them.