home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / asm / ucrstdlb / stdlib.txt < prev    next >
Text File  |  1991-10-13  |  175KB  |  5,201 lines

  1. ***************************************************************************
  2. *  UCR Standard Library v2.00   -- Release Date 10/12/91                  *
  3. ***************************************************************************
  4.  
  5.  
  6.  
  7. The UCR Standard Library for Assembly Language Programmers,
  8. Written By Randall Hyde and others, is
  9.  
  10.   sssssss      ss     ss       ss       sssssss     sssssss
  11.   ss           ss     ss      ssss      ss    ss    ss
  12.   ss           ss     ss     ss  ss     ss    ss    ss
  13.   sssssss      sssssssss    ssssssss    sssssss     sssss        ssssssss
  14.        ss      ss     ss    ss    ss    ss  ss      ss
  15.        ss      ss     ss    ss    ss    ss   ss     ss
  16.   sssssss      ss     ss    ss    ss    ss    ss    sssssss
  17.  
  18.  
  19.  
  20.   ww                  ww       ww       sssssss     sssssss
  21.    ww                ww       wwww      ss    ss    ss
  22.     ww      ww      ww       ww  ww     ss    ss    ss
  23.      ww    wwww    ww       wwwwwwww    sssssss     sssss
  24.       ww  ww  ww  ww        ww    ww    ss  ss      ss
  25.        wwww    wwww         ww    ww    ss   ss     ss
  26.         ww      ww          ww    ww    ss    ss    sssssss
  27.  
  28.  
  29.  
  30.  
  31. We do not want any registration fees for this software.
  32.  
  33. Now for the catch...  It is more blessed to give than to receive.  
  34. If this software saves you time and effort and you enjoy using it, 
  35. our lives will be enriched knowing that others have appreciated our work.  
  36. We would like to share this wonderful feeling with you.  If you like this 
  37. software and use it, we would like you to contribute at least one routine to 
  38. the library.  Perhaps you think this library has some neat-o routines in it.  
  39. Imagine how nice it would become if everyone used their imagination to 
  40. contribute something useful to it.
  41.  
  42. We hereby release this software to the public domain.  You can use it in any
  43. way you see fit.  However, we would appreciate it if you share this software 
  44. with others as much as it has been shared it with you.  That is not to suggest
  45. that you give away software you have written with this package (We're not 
  46. quite as crazy as Richard Stallman, bless his heart), but if someone else would 
  47. like a copy of this library, please help them out.  Naturally, we would be 
  48. tickeled pink to receive credit in software that uses these routines (which is 
  49. the honorable thing to do) but we understand the way many corporations operate 
  50. and won't be terribly put off if you use it without giving due credit.  
  51.  
  52. Enjoy!
  53.  
  54. If you have comments, bug reports, new code to contribute, etc., you can 
  55. reach us through:
  56.  
  57.         rhyde                (On BIX).
  58.         rhyde@ucrmath.ucr.edu        (On Internet).
  59.  
  60. or
  61.  
  62.         Randall Hyde
  63.         Dept of Computer Science
  64.         122 University Office Bldg
  65.         University of California
  66.         Riverside, Ca. 92521
  67.  
  68.  
  69. COMMENTS ABOUT THE CODE:
  70. ************************
  71.  
  72. Please don't expect super optimal code here.  Most of it is fairly mediocre 
  73. (from a size/speed point of view).  Hopefully, you'll agree, it's the idea 
  74. that counts.  If you do not like something I have done, you have got the 
  75. sources -- have at it.  (Of course, it would be appreciated if you would
  76. send any modifications to one of the E-MAIL addresses above.)
  77.  
  78.  
  79. COMMENTS ABOUT THIS DOCUMENTATION:
  80. **********************************
  81.  
  82. You will have to forgive us for the inconsistent style appearing throughout
  83. this document.  Keep in mind that this document has been prepared by many
  84. different people.  Keeping the styles consistent is a time consuming and
  85. difficult task.
  86.  
  87. Whenever a routine's description claims that the flags are not affected,
  88. you should not interpret this to mean that the routine preserves the flags.
  89. Most routines do *not* preserve any of the flags.  Such a statement simply
  90. means that the routine does not *explicitly* return a value in one (or more)
  91. of the flag bits.
  92.  
  93. Note that proper credit has been given to the author of each of the various
  94. routines appearing in this library *except* for those written by Randall
  95. Hyde.  All routines without an author by-line were probably written by
  96. Randall Hyde (unless we screwed up somewhere and forgot to put a name
  97. in the documentation).  Most of these routines were tested and documented
  98. by various students in Randy Hyde's CS 13 (assembly language) and CS 191X /
  99. CS 185 courses (Commercial Software Development).  There are too many names
  100. to mention here, but these students definitely deserve the credit for locating
  101. numerous bugs in the code, providing many suggestions, and doing other work.
  102.  
  103.  
  104. ROUTINES WE WOULD LIKE TO HAVE:
  105. *******************************
  106.  
  107. If you're interested in adding some routines to this
  108. package, GREAT!  Here are some suggestions.
  109.  
  110. 1) Routines which manipulate directories (read/write/etc.)
  111. 2) A regular expression interpreter.
  112. 3) Length-prefixed strings package.
  113. 4) A graphics package.
  114. 5) An object-oriented programming class library.
  115. 6) Just about anything else appearing in a HLL "standard" library.
  116. If you've got any ideas, we would  love to discuss them with you.  The best
  117. way to reach us is through the E-MAIL addresses above.
  118.  
  119.  
  120. MISSING ROUTINES TO BE SUPPLIED IN THE FUTURE:
  121. **********************************************
  122.  
  123. Character strings:
  124. trim-        Removes trailing blanks from a string.
  125. blkdel-        Removes leading blanks from a string.
  126. translit-    Transliterates characters in a string based on a translation
  127.         table.
  128.  
  129.  
  130. Pattern matching and character sets:
  131. span-        Skips through a sequence of characters in a string which
  132.         belong to a character set.
  133. break-        Skips through a sequence of characters in a string which do not
  134.         belong to a character set.
  135. any-        Skips over a character if it is a member of a set.
  136. notany-        Skips over a character in a string if it is not a member
  137.         of a set.
  138. skip-        Skips "n" characters in the string.
  139. tab-        Matches up to the nth character in a string.
  140. rtab-        Matches up to the nth character from the end of a string.
  141. pos-        Matches if we are currently at the nth position in a string.
  142. rpos-        Matches if we are at the nth position from the end of the
  143.         string.
  144. mark-        Marks a position in a string during pattern matching
  145. grab-        Copies everything from the last mark and creates a new string 
  146.         on the stack from this substring.
  147. match-        Initialize pattern matching system.
  148. alternate-    Try an alternative if the current pattern does not match.
  149. arb-        Skip over an arbitrary number of characters in a match.
  150. replace-    Replace a substring from the last mark to the current 
  151.         position with some other string.
  152. fail-        Force a match failure.
  153. succeed-    Force a match success.
  154.  
  155.  
  156.     Memory Manager Package
  157. Memavail-    Largest block of free memory available on the heap.
  158. Memfree-    Total amount of free space on the heap.
  159. BlockSize-    Returns the size of the memory block which es:di points at.
  160.  
  161.  
  162.     Structured Array Package
  163. aryalloc-    Allocate storage for a single dimension structured array.
  164. ary2alloc-    Allocate storage for a two dimension structured array.
  165. ary3alloc-    Allocate storage for a three dimension structured array.
  166. arynalloc-    Allocate storage for an n-dimensional structured array.
  167. aryaccess-    Access an element of a structured array.
  168. ary2access-    Access an element of a two-dimension structured array.
  169. ary3access-    Access an element of a three-dimension structured array.
  170. arynaccess-    Access an element of an n-dimensional structured array.
  171. copyarray-    Copy the elements of one structured array to another.
  172. duparray-    Duplicate a structured array on the heap.
  173. redim-        Redimension a structured array.
  174. aryfill-    Initialize an array with a list of values.
  175. cmpary-        Compares two structured arrays to see if they are equal.
  176.  
  177.  
  178.     Process Manager Package
  179. CoCall-        Call a coroutine.  
  180. CoInit-        Initialize a coroutine.
  181. CoRet-        Quit a coroutine.
  182.  
  183.  
  184. HOW TO USE THE STANDARD LIBRARY:
  185. ********************************
  186.  
  187. When you are ready to begin programming with the library, you should
  188. copy the shell.asm file, provided in the package, to another file in
  189. which you will be working, i.e. myprog.asm.  The shell.asm file sets
  190. up the machine (segments, etc.) as the UCR Standard Library expects
  191. them.  Results are undefined for other setups.  Therefore, I strongly
  192. suggest, that when you begin using these routines, you follow the
  193. shell.asm format.  Later, when you are familiar with the software,
  194. you may wish to create your own shell.asm file, but it is wise to
  195. initially use the one provided.  The shell.asm file has comments which
  196. tell you where to place your code, variables, etc.
  197.  
  198. There is an include file, stdlib.a (stdlib.a6 for MASM 6.0 users), which
  199. you should include in every assembly you perform which calls the stdlib
  200. routines.  SHELL.ASM already includes this file.  *YOU MUST PLACE THE
  201. INCLUDE STATEMENT OUTSIDE OF ANY SEGMENTS IN YOUR PROGRAM*.  Preferably
  202. as the first line of your program (just like SHELL.ASM).  If you place
  203. this include directive inside a segment, certain assemblers/linkers
  204. (especially MASM) will not properly assemble and link your programs.
  205. They will assemble and link without error, but the resulting program
  206. will not execute correctly.
  207.  
  208. The STDLIB.A file contains macros you can use to call each of the routines
  209. in the standard library.  For example, to call PRINTF you would use the
  210. statement
  211.         printf
  212.         db    "format string",0
  213.         db    other,vars
  214.  
  215. rather than "calling" printf.  Printf is actually a macro, you cannot call
  216. it directly (all of the standard library routines have names like "sl_printf"
  217. and the macro issues a call to the appropriate routine).  These macros have
  218. two main purposes-- first, the differentiate calls to the standard library
  219. routines (i.e., no "call" instruction is the difference); and second, they
  220. contain some extra code to perform "smart linking" with MASM 5.1 & earlier,
  221. TASM, and OPTASM.  MASM 6.0 supports a new directive, extrndef, which
  222. eliminates the need for this extra code, but the extra code works nonetheless.
  223. There is a special include file, STDLIB.A6, for MASM 6.0 users which is
  224. smaller and, therefore, speeds up assemblies and consumes less memory
  225. during assembly.
  226.  
  227. All of the standard library routines, and most of their local data values,
  228. are in a segment named "stdlib".  You should not create such a segment unless
  229. you plan on adding new routines to the standard library.
  230.  
  231.  
  232. HOW THE STANDARD LIBRARY IS ORGANIZED:
  233. **************************************
  234.  
  235. In the next several pages are the documentation spec sheets for each of the
  236. standard library routines.  The routines are listed by category.  The listing
  237. of the categories and their order in the documentation is below.
  238.  
  239.     Standard Input Routines
  240.     Standard Output Routines
  241.     Conversion Routines
  242.     Utility Routines
  243.     String Handling Routines
  244.     Memory Management Routines
  245.     Character Set Routines
  246.     Floating Point Routines
  247.  
  248. In addition, at the beginning of each of the category is a brief
  249. discussion of the purpose of its routines.
  250.  
  251.  
  252.  
  253.  
  254.  
  255. Character Input Routines
  256. ------------------------
  257.  
  258.  
  259.     The character input routines take input from either a standard
  260. device (keyboard, etc.) or a standard library.  After the character input
  261. routines receive the characters they either place the characters on the stack
  262. and/or return.  The character input routines work similar to the "C" character
  263. input routines.
  264.  
  265.  
  266.  
  267. Routine:  Getc
  268. --------------
  269.  
  270.  
  271. Category:             Character Input Routine
  272.  
  273.  
  274. Registers on Entry:   None
  275.  
  276.  
  277. Registers on Return:  AL- Character from input device.
  278.                       AH- 0 if eof, 1 if not eof.
  279.  
  280.  
  281. Flags Affected:       Carry- 0 if no error, 1 if error.  If error occurs, AX
  282.                              contains DOS error code.
  283.  
  284.  
  285. Example of Usage:  
  286.                       getc
  287.                       mov     KbdChar, al
  288.                       putc
  289.  
  290.  
  291. Description:  This routine reads a character from the standard input device.
  292.               This call is synchronous, that is, it does not return until a
  293.               character is available.  The Default input device is DOS
  294.               standard input.
  295.  
  296.               Getc returns two types of values: extended ASCII (codes 1-255)
  297.               and IBM keyboard scan codes.  If Getc returns a non-zero value,
  298.               you may interpret this value as an ASCII character.  If Getc
  299.               returns zero, you must call Getc again to get the actual
  300.               keypress.
  301.  
  302.               The second call returns an IBM PC keyboard scan code.
  303.  
  304.               Since the user may redirect input from the DOS command line,
  305.               there is the possibility of encountering end-of-file (eof)
  306.               when calling getc.  Getc uses the AH register to return eof
  307.               status.  AH contains the number of characters actually read
  308.               from the standard input device.  If it returns one, then
  309.               you've got a valid character.  If it returns zero, you've
  310.               reached end of file.  Note that pressing control-z forces an
  311.               end of file condition when reading data from the keyboard.
  312.  
  313.               This routine returns the carry flag clear if the operation
  314.               was successful.  It returns the carry flag set if some sort
  315.               of error occurred while reading the character.  Note that eof
  316.               is not an error condition.  Upon reaching the end of file,
  317.               Getc returns with the carry flag clear.  If getc is seen from
  318.               a file the control-z is not seen as an end-of-file marker,
  319.               but just read in as a character of the file.
  320.  
  321.               Control-c if read from a keyboard device aborts the program.
  322.               However if when reading something other than a keyboard
  323.               (files, serial ports), control-c from the input source
  324.               returns control-c.  However when pressing control-break
  325.               the program will abort regardless of the input source.
  326.  
  327.               Regarding CR/LF, if the input is from a device, (eg. keyboard
  328.               serial port) getc returns whatever that device driver returns,
  329.               (generally CR without a LF).  However if the input is from
  330.               a file, getc stripes a single LF if it immediately follows
  331.               the CR.
  332.  
  333.               When using getc files operate in "cooked" mode.  While
  334.               devices operate in "pseudo-cooked" mode, which means no
  335.               buffering, no CR -> CR/LF, but it handles control-c, and
  336.               control-z.
  337.  
  338.           See the sources for more information about GETC's internal
  339.           operation.
  340.  
  341. Include:    stdlib.a   
  342.  
  343.  
  344.  
  345.  
  346. Routine:   GetcStdIn
  347. --------------------
  348.  
  349.  
  350. Category:             Character Input Routine
  351.  
  352. Register on entry:    None.
  353.  
  354. Register on return:   AL- Character from input device.
  355.  
  356. Flags affected:       AH- 0 if eof, 1 if not eof.
  357.                       Carry- 0 if no error, 1 if error
  358.                       (AX contains DOS error code if error occurs).
  359.  
  360.  
  361. Example of Usage:   
  362.                       GetcStdIn
  363.                       mov     InputChr, al
  364.                       putc
  365.  
  366.  
  367. Description:    This routine reads a character from the DOS standard input
  368.                 device.  This call is synchronous, that is, it does not return
  369.                 until a character is available.  See the description of Getc
  370.                 above for more details.
  371.  
  372.         The difference between Getc and GetcStdIn is that your
  373.         program can redirect Getc using other calls in this library.
  374.         GetcStdIn calls DOS directly without going through this
  375.         redirection mechanism.
  376.  
  377.  
  378. Include:        stdlib.a
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385. Routine:   GetcBIOS
  386. -------------------
  387.  
  388.  
  389. Category:             Character Input Routine
  390.  
  391. Register on entry:    None
  392.  
  393. Register on return:   AL- Character from the keyboard.
  394.  
  395. Flags affected:       AH- 1 (always).  Carry- 0 (always).
  396.  
  397. Example of Usage:   
  398.                       GetcBIOS
  399.                       mov     CharRead, al
  400.                       putc
  401.  
  402.  
  403. Description:   This routine reads a character from the keyboard.  This call is
  404.                synchronous, that is it does not return until a character is
  405.                available.
  406.  
  407.         Note that there is no special character processing.  This
  408.         code does *not* check for EOF, control-C, or anything
  409.         else like that.
  410.  
  411.  
  412.  
  413. Include:        stdlib.a
  414.  
  415.  
  416.  
  417. Routine:  SetInAdrs
  418. -------------------
  419.  
  420. Category:               Character Input Routine
  421.  
  422. Registers on Entry:     ES:DI - address of new input routine
  423.  
  424. Registers on return:    None 
  425.  
  426. Flags affected:
  427.  
  428. Examples of Usage:
  429.  
  430.                         mov     es, seg NewInputRoutine
  431.                         mov     di, offset NewInputRoutine
  432.                         SetInAdrs
  433.  
  434.  
  435.  
  436.                         les     di, RoutinePtr
  437.                         SetInAdrs
  438.  
  439.  
  440. Description:    This routine redirects the stdlib standard input so that it 
  441.                 calls the routine who's address you pass in es:di.  The
  442.         routine (whose address appears in es:di) should be a "getc"
  443.         routine which reads a character from somewhere and returns
  444.         that character in AL.  It should also return EOF status in
  445.         the AH register and error status in the carry flag (see
  446.         the description of GETC for more details).
  447.  
  448.  
  449. Include:                stdlib.a
  450.  
  451.  
  452.  
  453.  
  454.  
  455. Routine:   GetInAdrs
  456. --------------------
  457.  
  458. Category:             Character Input Routine
  459.  
  460. Register on entry:    None
  461.  
  462. Register on return:   ES:DI - address of current input routine (called by Getc).
  463.  
  464. Flags affected:       None
  465.  
  466.  
  467. Example of Usage:   
  468.                       GetInAdrs
  469.                       mov     word ptr SaveInAdrs, di
  470.                       mov     word ptr SaveInAdrs+2, es
  471.  
  472.  
  473. Description:   You can use this function to get the address of the current
  474.                input routine, perhaps so you can save it or see if it is
  475.                currently pointing at some particular piece of code.
  476.                If you want to temporarily redirect the input and then restore
  477.                the original input or outline, consider using
  478.                PushInAdrs/PopInAdrs described later.
  479.  
  480.  
  481. Include:        stdlib.a
  482.  
  483.  
  484.  
  485. Routine:   PushInAdrs
  486. ---------------------
  487.  
  488. Category:             Character Input Routine
  489.  
  490. Register on entry:    ES:DI - Address of new input routine.
  491.  
  492. Register on return:   Carry=0 if operation successful.
  493.                       Carry=1 if there were already 16 items on the stack.
  494.                          
  495. Example of Usage:   
  496.                       mov     es, seg NewInputRoutine
  497.                       mov     di, offset NewInputRoutine
  498.                       PushInAdrs
  499.                         .
  500.                         .
  501.                         .
  502.                       les     di, RoutinePtr
  503.                       PushInAdrs
  504.  
  505.  
  506. Description:   This routine "pushes" the current input address onto an
  507.                internal stack and then copies the value in es:di into the
  508.                current input routine pointer.  The PushInAdrs and PopInAdrs
  509.                routines let you easily save and redirect the standard output
  510.                and then restore the original output routine address later on.
  511.                If you attempt to push more than 16 items on the stack,
  512.                PushInAdrs will ignore your request and return with the
  513.                carry flag set.  If PushInAdrs is successful, it will
  514.                return with the carry flag clear.
  515.  
  516.  
  517. Include:    stdlib.a
  518.  
  519.  
  520.  
  521.  
  522.  
  523. Routine:   PopInAdrs
  524. --------------------
  525.  
  526. Category:             Character Input Routine
  527.  
  528. Register on entry:    None
  529.  
  530. Register on return:   ES:DI - Points at the previous stdout routine before
  531.                       the pop.
  532.  
  533. Example of Usage:   
  534.                       mov     es, seg NewInRoutine
  535.                       mov     di, offset NewInputRoutine
  536.                       PushInAdrs
  537.                         .
  538.                         .
  539.                         .
  540.                       PopInAdrs
  541.  
  542.  
  543. Description:   PopInAdrs undoes the effects of PushInAdrs.  It pops an item
  544.                off the internal stack and stores it into the input routine
  545.                pointer.  The previous value in the output pointer is returned
  546.                in es:di.
  547.  
  548. Include:    stdlib.a
  549.  
  550.  
  551.  
  552.  
  553.  
  554. Routine:  Gets, Getsm
  555. ---------------------
  556.  
  557. Category:             Character Input Routine
  558.  
  559. Register on entry:    ES:DI- Pointer to input buffer (gets only).
  560.  
  561. Register on return:   ES:DI - address of input of text.
  562.                       carry-  0 if no error, 1 if error.
  563.                       If error, AX contains: 0- End of
  564.                       file encountered in middle of
  565.                       string.  1- Memory allocation error (getsm only).
  566.                       Other- DOS error code.
  567.  
  568.  
  569. Flags affected:       None
  570.  
  571. Example of usage:    
  572.                       getsm           ;Read a string from the
  573.                                       ;keyboard
  574.                       puts            ;Print it
  575.                       putcr           ;Print a new line
  576.                       free            ;Deallocate storage for
  577.                                       ;string.
  578.  
  579.               mov    di, seg buffer
  580.               mov    es, di
  581.               lea    di, buffer
  582.               gets
  583.               puts
  584.               putcr
  585.  
  586.  
  587. Description:       Reads a line of text from the stdlib standard input device.
  588.         You must pass a pointer to the recipient buffer in es:di to
  589.         the GETS routine.  GETSM automatically allocates storage for
  590.         the string on the heap (up to 256 bytes) and returns a pointer
  591.         to this block in es:di.
  592.  
  593.         Gets(m) returns all characters typed by the user except for the
  594.         carriage return (ENTER) key code.  These routines return a
  595.         zero-terminated string (with es:di pointing at the string).
  596.         Exactly how Gets(m) treats the incoming data depends upon
  597.         the source device, however, you can usually count on Gets(m)
  598.         properly handling backspace (erases previous character),
  599.         escape (erase entire line), and ENTER (accept current line).
  600.  
  601.         Other keys may affect Gets(m) as well.  For example, Gets(m),
  602.         by default, calls Getc which, in turn, usually calls DOS'
  603.         standard input routine.  If you type control-C or break while
  604.         read from DOS' standard input it may abort the program.
  605.  
  606.         If an error occurs during input (e.g., EOF encountered in
  607.         the middle of a line) Gets(m) returns the error code in
  608.         AX.  If no error occurs, Gets(m) preserves AX.
  609.  
  610. Include:                  stdlib.a
  611.  
  612.  
  613.  
  614.  
  615.  
  616. Routine:  Scanf
  617. ---------------
  618.  
  619. Category:             Character Input Routine
  620.  
  621. Register on entry:    None
  622.  
  623. Register on return:   None
  624.  
  625. Flags affected:       None
  626.  
  627. Example of usage:   
  628.                       scanf
  629.                       db      "%i  %h  %^s",0
  630.                       dd      i, x, sptr
  631.  
  632. Description:   * Formatted input from stdlib standard input.
  633.                * Similar to C's scanf routine.
  634.                * Converts ASCII to integer, unsigned, character, string, hex,
  635.                  and long values of the above.
  636.                Scanf provides formatted input in a fashion analogous to
  637.                printf's output facilities.  Actually, it turns out that scanf
  638.                is considerably less useful than printf because it doesn't
  639.                provide reasonable error checking facilities (neither does C's
  640.                version of this routine).  But for quick and dirty programs 
  641.                whose input can be controlled in a rigid fashion (or if you're
  642.                willing to live by "garbage in, garbage out")  scanf provides 
  643.                a convenient way to get input from the user.  Like printf, the
  644.                scanf routine expects you to follow the call with a format 
  645.                string and then a list of (far pointer) memory addresses.  The
  646.                items in the scanf format string take the following form: %^f,
  647.                where f represents d, i, x, h, u, c, x, ld, li, lx, or lu.  
  648.                Like printf, the "^" symbol tells scanf that the address
  649.                following the format string is the address of a (far) pointer
  650.                to the data rather than the address of the data location itself.
  651.                By default, scanf automatically skips any leading whitespace 
  652.                before attempting to read a numeric value.  You can instruct
  653.                scanf to skip other characters by placing that character in the
  654.                format string.  For example, the following call instructs scanf
  655.                to read three integers separated by commas (and/or whitespace):
  656.  
  657.                                  scanf  
  658.                   db                "%i,%i,%i",0
  659.                               dd                 i1,i2,i3
  660.  
  661.                Whenever scanf encounters a non-blank character in the format
  662.                string, it will skip that character (including multiple
  663.                occurrences of that character) if it appears next in the input
  664.                stream.  Scanf always calls gets to read a new line of text 
  665.                from stdlib's standard input.  If scanf exhausts the format 
  666.                list, it ignores any remaining characters on the line.  If
  667.                scanf exhausts the input line before processing all of the
  668.                format items, it leaves the remaining variables unchanged.
  669.                Scanf always deallocates the storage allocated by gets.
  670.  
  671.  
  672. Include:                stdlib.a
  673.  
  674.  
  675.  
  676.  
  677. Character Output Routines
  678. -------------------------
  679.  
  680.  
  681. The stdlib character output routines allow you to print to the 
  682. standard output device.  Although the processing of non-ASCII 
  683. characters is undefined, most output devices handle these characters
  684. properly.  In particular, they can handle return, line feed, back space, 
  685. and tab.  
  686.  
  687. Most of the output routines in the standard library output data 
  688. through the Putc routine.  They generally use the AX register upon 
  689. entry and print the character(s) to the standard output device by
  690. calling DOS by default. The  output is redirectable to the 
  691. user-written routine.  However, the PutcBIOS routine prints doesn't 
  692. use DOS.  Instead it uses BIOS routines to print the character in AL 
  693. using the INT command for teletype-like output. 
  694.  
  695. The print routines are similar to those in C, however, they differ
  696. in their implementation. The print routine returns to the address
  697. immediately following the terminating byte, therefore, it is important
  698. to remember to terminate your string with zero or you will print an 
  699. unexpected sequence of characters.
  700.  
  701.  
  702.  
  703. Routine:  Putc
  704. --------------
  705.  
  706. Category:             Character Output Routine
  707.  
  708. Registers on Entry:   AL- character to output
  709.  
  710. Registers on Return:  None
  711.  
  712. Flags affected:       None
  713.  
  714. Example of Usage:
  715.                        mov     al, 'C'
  716.                        putc                    ;Prints "C" to std output.
  717.  
  718.  
  719. Description:  Putc is the primitive character output routine.  Most other
  720.               output routines in the standard library output data through
  721.               this procedure.  It prints the ASCII character in AL register.  
  722.               The processing of control codes is undefined although most output
  723.               routines this routine links to should be able to handle return, 
  724.               line feed, back space, and tab.  By default, this routine calls
  725.               DOS to print the character to the standard output device.  The
  726.               output is redirectable to to user-written routine.
  727.  
  728.  
  729. Include:                stdlib.a
  730.  
  731.  
  732.  
  733. Routine:  PutCR
  734. ---------------
  735.  
  736. Category:             Character Output Routine 
  737.  
  738. Register on entry:    None
  739.  
  740. Register on return:   None
  741.  
  742. Flags affected:       None
  743.  
  744. Example of Usage:     PutCR
  745.  
  746.  
  747. Description:  Using PutCR is an easy way of printing a newline to the stdlib 
  748.               standard output. It prints a newline (carriage return/line feed) 
  749.               to the current standard output device.
  750.  
  751.  
  752. Include:                stdlib.a
  753.  
  754.  
  755. Routine: PutcStdOut
  756. -------------------
  757.  
  758. Category:              Character Output Routine
  759.  
  760. Registers on Entry:    AL- character to output
  761.  
  762. Registers on Return:   None
  763.  
  764. Flags Affected:        None
  765.  
  766. Example of Usage:
  767.                        mov AL, 'C'
  768.                        PutcStdOut        ; Writes "C" to standard output
  769.  
  770.  
  771. Description:  PutcStdOut calls DOS to print the character in AL to the standard
  772.               output device.  Although processing of non-ASCII characters and
  773.               control characters is undefined, most output devices handle these
  774.               characters properly.  In particular, most output devices properly
  775.               handle return, line feed, back space, and tab.  The output is
  776.               redirectable via DOS I/O redirection.
  777.  
  778.  
  779. Include:                stdlib.a
  780.  
  781.  
  782.  
  783. Routine: PutcBIOS
  784. -----------------
  785.  
  786. Category:              Character Output Routine
  787.  
  788. Registers on Entry:    AL- character to print
  789.  
  790. Registers on Return:   None
  791.  
  792. Flags Affected:        None
  793.  
  794. Example of Usage:
  795.                        mov AL, "C"
  796.                        PutcBIOS
  797.  
  798.  
  799. Description:  PutcBIOS prints the character in AL using the BIOS routines,
  800.               using INT 10H/AH=14 for teletype-like output.  Output through
  801.               this routine cannot be redirected; such output is always sent
  802.               to the video display on the PC (unless, of course, someone has
  803.               patched INT 10h).  Handles return, line feed, back space, and
  804.               tab.  Prints other control characters using the IBM Character
  805.           set.
  806.  
  807.  
  808. Include:         stdlib.a
  809.  
  810.  
  811.  
  812. Routine: GetOutAdrs
  813. -------------------
  814.  
  815. Category:             Character Output Routine
  816.  
  817. Registers on Entry:   None
  818.  
  819. Registers on Return:  ES:DI- address of current output routine (called by Putc)
  820.  
  821. Flags Affected:       None
  822.  
  823. Example of Usage: 
  824.                       GetOutAdrs
  825.                       mov word ptr SaveOutAdrs, DI
  826.                       mov word ptr SaveOutAdrs+2, ES
  827.  
  828. Description:  GetOutAdrs gets the address of the current output routine, perhaps
  829.               so you can save it or see if it is currently pointing at some
  830.               particular piece of code.  If you want to temporarily redirect
  831.               the output and then restore the original output routine, consider
  832.               using PushOutAdrs/PopOutAdrs described later.
  833.  
  834. Include:    stdlib.a
  835.  
  836.  
  837.  
  838.  
  839. Routine:  SetOutAdrs
  840. --------------------
  841.  
  842. Category:               Character Output Routine
  843.  
  844. Registers on Entry:     ES:DI - address of new output routine
  845.  
  846. Registers on return:    None 
  847.  
  848. Flags affected:         None
  849.  
  850. Example of Usage:
  851.  
  852.                         mov     es, seg NewOutputRoutine
  853.                         mov     di, offset NewOutputRoutine
  854.                         SetOutAdrs
  855.                         les     di, RoutinePtr
  856.                         SetOutAdrs
  857.  
  858. Description:  This routine redirects the stdlib standard output so that it
  859.               calls the routine who's address you pass in es:di.  This routine
  860.               expects the character to be in AL and must preserve all registers.
  861.               It handles the printable ASCII characters and the four control
  862.               characters return, line feed, back space, and tab.  (The routine
  863.               may be modified in the case that you wish to handle these codes
  864.               in a different fashion.)
  865.  
  866.  
  867. Include:        stdlib.a
  868.  
  869.  
  870. Routine:  PushOutAdrs
  871. ---------------------
  872.  
  873. Category:              Character Output Routine 
  874.  
  875. Registers on Entry:    ES:DI- Address of new output routine
  876.  
  877. Registers on Return:   None
  878.  
  879. Flags Affected:        Carry = 0 if operation is successful
  880.                        Carry = 1 if there were already 16 items on the stack
  881.  
  882. Example of Usage:  
  883.                        mov  ES, seg NewOutputRoutine
  884.                        mov  DI, offset NewOutputRoutine
  885.                        PushOutAdrs
  886.                           .
  887.                           .
  888.                           . 
  889.                        les  DI, RoutinePtr
  890.                        PushOutAdrs
  891.  
  892.  
  893. Description:  This routine "pushes" the current output address onto an internal
  894.               stack and then uses the value in es:di as the current output
  895.               routine address.  The PushOutAdrs and PopOutAdrs routines let you
  896.               easily save and redirect the standard output and then restore the
  897.               original output routine address later on.  If you attempt to push
  898.               more than 16 items on the stack, PushOutAdrs will ignore your
  899.               request and return with the carry flag set.  If PushOutAdrs is
  900.               successful, it will return with the carry flag clear.
  901.  
  902.  
  903. Include:          stdlib.a
  904.  
  905.  
  906.  
  907. Routine:  PopOutAdrs
  908. --------------------
  909.  
  910. Category:             Character Output Routine 
  911.  
  912. Registers on Entry:   None
  913.  
  914. Registers on Return:  ES:DI- Points at the previous stdout routine before
  915.                       the pop
  916.  
  917. Flags Affected:       None
  918.  
  919. Example of Usage:  
  920.                       mov ES, seg NewOutputRoutine
  921.                       mov DI, offset NewOutputRoutine
  922.                       PushOutAdrs
  923.                          .
  924.                          .
  925.                          .
  926.                       PopOutAdrs
  927.  
  928.  
  929. Description:  PopOutAdrs undoes the effects of PushOutAdrs.  It pops an item off
  930.               the internal stack and stores it into the output routine pointer.
  931.               The previous value in the output pointer is returned in es:di.
  932.               Defaults to PutcStdOut if you attempt to pop too many items off
  933.               the stack.
  934.  
  935. Include:    stdlib.a
  936.  
  937.  
  938.  
  939.  
  940. Routine:  Puts
  941. --------------
  942.  
  943. Category:            Character Output Routine 
  944.  
  945. Register on entry:   ES:DI register - contains the address of the string
  946.  
  947. Register on return:  None
  948.  
  949. Flags affected:      None
  950.  
  951. Example of Usage:
  952.                      les     di, StrToPrt
  953.                      puts
  954.                      putcr
  955.  
  956.  
  957. Description:   Puts prints a zero-terminated string whose address appears
  958.                in es:di.  Each character appearing in the string is printed
  959.                verbatim.  There are no special escape characters.  Unlike
  960.                the "C" routine by the same name, puts does not print a
  961.                newline after printing the string.  Use putcr if you want
  962.                to print the newline after printing a string with puts.
  963.  
  964.  
  965. Include:        stdlib.a
  966.  
  967.  
  968.  
  969. Routine:  Puth
  970. --------------
  971.  
  972. Category:             Character Output Routine
  973.  
  974. Register on entry:    AL 
  975.  
  976. Register on return:   AL
  977.  
  978. Flags affected:       None
  979.  
  980. Example of Usage:
  981.                       mov     al, 1fh
  982.                       puth
  983.  
  984.  
  985. Description:    The Puth routine Prints the value in the AL register as two
  986.                 hexadecimal digits.  If the value in AL is between 0 and 0Fh, 
  987.                 puth will print a leading zero.  This routine calls the stdlib
  988.                 standard output routine (putc) to print all characters.
  989.  
  990.  
  991. Include:        stdlib.a 
  992.  
  993.  
  994.  
  995. Routine:  Putw
  996. --------------
  997.  
  998. Category:             Character Output Routine
  999.  
  1000. Registers on Entry:   AX- Value to print
  1001.  
  1002. Registers on Return:  None
  1003.  
  1004. Flags Affected:       None
  1005.  
  1006. Example of Usage: 
  1007.                       mov AX, 0f1fh
  1008.                       putw
  1009.  
  1010.  
  1011. Description:  The Putw routine prints the value in the AX register as four
  1012.               hexadecimal digits (including leading zeros if necessary).  
  1013.               This routine calls the stdlib standard output routine (putc) 
  1014.               to print all characters.
  1015.  
  1016. Include:        stdlib.a
  1017.  
  1018.  
  1019.  
  1020. Routine:  Puti
  1021. --------------
  1022.  
  1023. Category:             Character Output Routine
  1024.  
  1025. Registers on Entry:   AX- Value to print
  1026.  
  1027. Registers on Return:  None
  1028.  
  1029. Flags Affected:       None
  1030.  
  1031. Example of Usage: 
  1032.                       mov AX, -1234
  1033.                       puti
  1034.  
  1035.  
  1036. Description:  Puti prints the value in the AX register as a decimal integer.
  1037.               This routine uses the exact number of screen positions required
  1038.               to print the number (including a position for the minus sign, if
  1039.               the number is negative).  This routine calls the stdlib standard
  1040.               output routine (putc) to print all characters.
  1041.  
  1042.  
  1043. Include:        stdlib.a
  1044.  
  1045.  
  1046.  
  1047. Routine:  Putu
  1048. --------------
  1049.  
  1050. Category:             Character Output Routine
  1051.  
  1052. Register on entry:    AX- Unsigned value to print.
  1053.  
  1054. Register on return:   None
  1055.  
  1056. Flags affected:       None
  1057.  
  1058. Example of Usage:
  1059.                       mov     ax, 1234
  1060.                       putu
  1061.  
  1062.  
  1063. Description:  Putu prints the value in the AX register as an unsigned integer.
  1064.               This routine uses the exact number of screen positions required
  1065.               to print the number.  This routine calls the stdlib standard
  1066.               output routine (putc) to print all characters.
  1067.  
  1068.  
  1069. Include:        stdlib.a
  1070.  
  1071.  
  1072.  
  1073.  
  1074. Routine:  Putl
  1075. --------------
  1076.  
  1077. Category:            Character Output Routine
  1078.  
  1079. Register on entry:   DX:AX- Value to print
  1080.  
  1081. Register on return:  None
  1082.  
  1083. Flags affected:      None
  1084.  
  1085. Example of Usage:
  1086.                      mov     dx, 0ffffh
  1087.                      mov     ax, -1234
  1088.                      putl
  1089.  
  1090.  
  1091. Description:   Putl prints the value in the DX:AX registers as an integer.
  1092.                This routine uses the exact number of screen positions
  1093.                required to print the number (including a position for the
  1094.                minus sign, if the number is negative).  This routine calls
  1095.                the stdlib standard output routine (putc) to print all
  1096.                characters.
  1097.  
  1098.  
  1099. Include:        stdlib.a
  1100.  
  1101.  
  1102.  
  1103. Routine:  Putul
  1104. ---------------
  1105.  
  1106. Category:             Character Output Routine
  1107.  
  1108. Register on entry:    DX:AX register
  1109.  
  1110. Register on return:   None
  1111.  
  1112. Flags affected:       None
  1113.  
  1114. Example of Usage:
  1115.                       mov     dx, 12h
  1116.                       mov     ax, 1234
  1117.                       putul
  1118.  
  1119.  
  1120. Description:    Putul prints the value in the DX:AX registers as an unsigned
  1121.                 integer.  This routine uses the exact number of screen
  1122.                 positions required to print the number.  This routine calls 
  1123.         the stdlib standard output routine (putc) to print all
  1124.         characters.
  1125.  
  1126.  
  1127. Include:        stdlib.a
  1128.  
  1129.  
  1130. Routine:  PutISize
  1131. ------------------
  1132.  
  1133. Category:              Character Output Routine
  1134.  
  1135. Registers on Entry:    AX - Integer value to print
  1136.                        CX - Minimum number of print positions to use
  1137.  
  1138. Registers on return:   None 
  1139.  
  1140. Flags affected:
  1141.  
  1142. Example of Usage:
  1143.                        mov     cx, 5
  1144.                        mov     ax, I
  1145.                        PutISize
  1146.                            .
  1147.                            . 
  1148.                            .
  1149.                        mov     cx, 12
  1150.                        mov     ax, J
  1151.                        PutISize
  1152.  
  1153.  
  1154. Description:    PutISize prints the signed integer value in AX to the
  1155.                 stdlib standard output device using a minimum of n print
  1156.                 positions.  CX contains n, the minimum field width for the
  1157.                 output value.  The number (including any necessary minus sign)
  1158.                 is printed right justified in the output field.
  1159.                 If the number in AX requires more print positions than
  1160.                 specified by CX, PutISize uses however many print positions
  1161.                 are necessary to actually print the number.  If you specify
  1162.                 zero in CX, PutISize uses the minimum number of print positions
  1163.                 required.  Of course, PutI will also use the minimum number
  1164.                 of print positions without disturbing the value in the CX
  1165.                 register.
  1166.  
  1167.                 Note that, under no circumstances, will the number in AX
  1168.                 ever require more than 6 print positions (-32,767 requires
  1169.                 the most print positions).
  1170.  
  1171.  
  1172. Include:        stdlib.a
  1173.  
  1174.  
  1175.  
  1176. Routine:  PutUSize
  1177. ------------------
  1178.  
  1179. Category:              Character Output Routine
  1180.  
  1181. Registers on entry:    AX- Value to print
  1182.                CX- Minimum field width
  1183.  
  1184. Registers on return:   None
  1185.  
  1186. Flags affected:        None
  1187.  
  1188. Example of usage: 
  1189.                        mov     cx, 8
  1190.                        mov     ax, U
  1191.                        PutUSize
  1192.  
  1193.  
  1194. Description:  PutUSize prints the value in AX as an unsigned decimal integer.
  1195.               The minimum field width specified by the value in CX.
  1196.               Like PutISize above except this one prints unsigned values.  
  1197.               Note that the maximum number of print positions required by any 
  1198.               number (e.g., 65,535) is five.
  1199.  
  1200.  
  1201. Include:        stdlib.a
  1202.  
  1203.  
  1204.  
  1205. Routine:  PutLSize
  1206. ------------------
  1207.  
  1208. Category:            Character Output Routine
  1209.  
  1210. Register on entry:   DX:AX-32 bit value to print
  1211.              CX- Minimum field width
  1212.  
  1213. Register on return:  None
  1214.  
  1215. Flags affected:      None
  1216.  
  1217. Example of Usage:
  1218.                      mov     cx, 16
  1219.                      mov     dx, word ptr L+2
  1220.                      mov     ax, word ptr L
  1221.                      PutLSize
  1222.  
  1223.  
  1224. Description:   PutLSize is similar to PutISize, except this prints the long 
  1225.                integer value in DX:AX.  Note that there may be as many as 
  1226.                11 print positions (e.g., -1,000,000,000).
  1227.  
  1228. Include:        stdlib.a
  1229.  
  1230.  
  1231.  
  1232.  
  1233. Routine:  PutULSize
  1234. -------------------
  1235.  
  1236.  
  1237. Category:            Character Output Routine
  1238.  
  1239.  
  1240. Register on entry:   AX : DX and CX
  1241.  
  1242.  
  1243. Register on return:  None
  1244.  
  1245.  
  1246. Flags affected:      None
  1247.  
  1248.  
  1249. Example of usage:    mov     cx, 8
  1250.                      mov     dx, word ptr UL+2
  1251.                      mov     ax, word ptr UL
  1252.                      PutULSize
  1253.  
  1254.  
  1255. Description:  Prints the value in DX:AX as a long unsigned decimal integer.
  1256.               Prints the number in a minimum field width specified by the
  1257.               value in CX.  Just like PutLSize above except this one prints
  1258.               unsigned numbers rather than signed long integers.  The largest
  1259.               field width for such a value is 10 print positions.
  1260.  
  1261.  
  1262. Include:        stdlib.a
  1263.  
  1264.  
  1265. Routine:   Print
  1266. ----------------
  1267.  
  1268. Category:             Character Output Routine
  1269.  
  1270. Register on entry:    CS:RET - Return address points at the string to print.
  1271.  
  1272. Register on return:   None
  1273.  
  1274. Flags affected:       None
  1275.  
  1276. Examples of Usage:    print
  1277.                       db      "Print this string to the display device"
  1278.                       db      13,10
  1279.                       db      "This appears on a new line"
  1280.                       db      13,10
  1281.                       db      0
  1282.  
  1283.  
  1284. Description:   Print lets you print string literals in a convenient
  1285.                fashion.  The string to print immediately follows the call
  1286.                to the print routine.  The string must contain a
  1287.                zero terminating byte and may not contain any intervening
  1288.                zero bytes.  Since the print routine returns to the address
  1289.                immediately following the zero terminating byte, forgetting
  1290.                this byte or attempting to print a zero byte in the middle
  1291.                of a literal string will cause print to return to an
  1292.                unexpected instruction.  This usually hangs up the machine.
  1293.                Be very careful when using this routine!
  1294.  
  1295.  
  1296. Include:        stdlib.a
  1297.  
  1298.  
  1299. Routine:        Printf
  1300. ---------------------
  1301.  
  1302. Category:             Character Output Routine
  1303.  
  1304. Register on entry:    CS:RET - Return address points at the format string
  1305.  
  1306. Register on return:   None
  1307.  
  1308. Flags affected:       None
  1309.  
  1310. Example of Usage:
  1311.                       printf
  1312.                       db      "Indirect access to i: %^d",13,10,0
  1313.                       dd      IPtr;
  1314.                       printf
  1315.                       db      "A string allocated on the heap: %-\.32^s"
  1316.                       db      13,10,0
  1317.                       dd      SPtr
  1318.  
  1319.  
  1320.  
  1321. Descriptions:   Printf, like its "C" namesake, provides formatted output
  1322.                 capabilities for the stdlib package.  A typical call to printf
  1323.                 always takes the following form:
  1324.  
  1325.                         printf
  1326.                         db              "format string",0
  1327.                         dd              operand1, operand2, ..., operandn
  1328.  
  1329.                 The format string is comparable to the one provided in the
  1330.                 "C" programming language.  For most characters, printf simply
  1331.                 prints the characters in the format string up to the
  1332.                 terminating zero byte.  The two exceptions are characters
  1333.                 prefixed by a backslash ("\") and characters prefixed by a
  1334.                 percent sign ("%").  Like C's printf, stdlib's printf uses
  1335.                 the backslash as an escape character and the percent sign as
  1336.                 a lead-in to a format string.
  1337.  
  1338.                 Printf uses the escape character ("\") to print special
  1339.                 characters in a fashion similar to, but not identical to C's
  1340.                 printf.  Stdlib's printf routine supports the following
  1341.                 special characters:
  1342.  
  1343.                 *  r     Print a carriage return (but no line feed)
  1344.                 *  n     Print a new line character (carriage return/line feed).
  1345.                 *  b     Print a backspace character.
  1346.                 *  t     Print a tab character.
  1347.                 *  l     Print a line feed character (but no carriage return).
  1348.                 *  f     Print a form feed character.
  1349.                 *  \     Print the backslash character.
  1350.                 *  %     Print the percent sign character.
  1351.                 *  0xhh  Print ASCII code hh, represented by two hex digits.
  1352.  
  1353.                 C users should note a couple of differences between stdlib's
  1354.                 escape sequences and C's.  First, use "\%" to print a percent
  1355.                 sign within a format string, not "%%".  C doesn't allow the
  1356.                 use of "\%" because the C compiler processes "\%" at compile
  1357.                 time (leaving a single "%" in the object code) whereas printf
  1358.                 processes the format string at run-time.  It would see a single
  1359.                 "%" and treat it as a format lead-in character.  Stdlib's
  1360.                 printf, on the other hand, processes both the "\" and "%" and
  1361.                 run-time, therefore it can distinguish "\%".
  1362.  
  1363.                 Strings of the form "\0xhh" must contain exactly two hex
  1364.                 digits.  The current printf routine isn't robust enough to
  1365.                 handle sequences of the form "\0xh" which contain only a
  1366.                 single hex digit.  Keep this in mind if you find printf
  1367.                 chopping off characters after you print a value.
  1368.  
  1369.                 There is absolutely no reason to use any escape character
  1370.                 sequences except "\0x00".  Printf grabs all characters
  1371.                 following the call to printf up to the terminating zero byte
  1372.                 (which is why you'd need to use "\0x00" if you want to print
  1373.                 the null character, printf will not print such values).
  1374.                 Stdlib's printf routine doesn't care how those characters got
  1375.                 there.  In particular, you are not limited to using a single
  1376.                 string after the printf call.  The following is perfectly
  1377.         legal:
  1378.  
  1379.  
  1380.                 printf
  1381.                 db      "This is a string",13,10
  1382.                 db      "This is on a new line",13,10
  1383.                 db      "Print a backspace at the end of this line:"
  1384.                 db      8,13,10,0
  1385.  
  1386.  
  1387.                 Your code will run a tiny amount faster if you avoid the use
  1388.                 of the escape character sequences.  More importantly, the
  1389.                 escape character sequences take at least two bytes.  You can
  1390.                 encode most of them as a single byte by simply embedding the
  1391.                 ASCII code for that byte directly into the code stream.
  1392.                 Don't forget, you cannot embed a zero byte into the code
  1393.                 stream.  A zero byte terminates the format string.  Instead,
  1394.                 use the "\0x00" escape sequence.
  1395.  
  1396.                 Format sequences always between with "%".  For each format
  1397.                 sequence you must provide a far pointer to the associated
  1398.                 data immediately following the format string, e.g.,
  1399.  
  1400.                     printf
  1401.                     db      "%i %i",0
  1402.                     dd      i,j
  1403.  
  1404.                 Format sequences take the general form "%s\cn^f" where:
  1405.  
  1406.                 *       "%" is always the "%" character.  Use "\%" if you
  1407.                         actually want to print a percent sign.
  1408.                 *       s is either nothing or a minus sign ("-").
  1409.                 *       "\c" is also optional, it may or may not appear in
  1410.                         the format item.  "c" represents any printable
  1411.                         character.
  1412.                 *       "n" represents a string of 1 or more decimal digits.
  1413.                 *       "^" is just the caret (up-arrow) character.
  1414.                 *       "f" represents one of the format characters: i, d, x,
  1415.                         h, u, c, s, ld, li, lx, or lu.
  1416.  
  1417.                 The "s", "\c", "n", and "^" items are optional, the "%" and
  1418.                 "f" items must be present.  Furthermore, the order of these
  1419.                 items in the format item is very important.  The "\c" entry,
  1420.                 for example, cannot precede the "s" entry.  Likewise, the "^"
  1421.                 character, if present, must follow everything except the "f"
  1422.                 character(s).
  1423.  
  1424.                 The format characters i, d, x, h, u, c, s, ld, li, lx, and
  1425.                 lu control the output format for the data.  The i and d
  1426.                 format characters perform identical functions, they tell
  1427.                 printf to print the following value as a 16-bit signed
  1428.                 decimal integer.  The x and h format characters instruct
  1429.                 printf to print the specified value as a 16-bit or 8-bit
  1430.                 hexadecimal value (respectively).  If you specify u, printf
  1431.                 prints the value as a 16-bit unsigned decimal integer.
  1432.                 Using c tells printf to print the value as a single character.
  1433.                 S tells printf that you're supplying the address of a
  1434.                 zero-terminated character string, printf prints that string.
  1435.                 The ld, li, lx, and lu entries are long (32-bit) versions of
  1436.                 d/i, x, and u.  The corresponding address points at a 32-bit
  1437.                 value which printf will format and print to the standard output.
  1438.                 The following example demonstrates these format items:
  1439.  
  1440.                 printf
  1441.                 db      "I= %i, U= %u, HexC= %h, HexI= %x, C= %c, "
  1442.                 db      "S= %s",13,10
  1443.                 db      "L= %ld",13,10,0
  1444.                 dd      i,u,c,i,c,s,l
  1445.  
  1446.                 The number of far addresses (specified by operands to the "dd"
  1447.                 pseudo-opcode) must match the number of "%" format items in
  1448.                 the format string.  Printf counts the number of "%" format
  1449.                 items in the format string and skips over this many far
  1450.                 addresses following the format string.  If the number of
  1451.                 items do not match, the return address for printf will be
  1452.                 incorrect and the program will probably hang or otherwise
  1453.                 malfunction.  Likewise (as for the print routine), the format
  1454.                 string must end with a zero byte.  The addresses of the items
  1455.                 following the format string must point directly at the memory
  1456.                 locations where the specified data lies.
  1457.  
  1458.                 When used in the format above, printf always prints the
  1459.                 values using the minimum number of print positions for each
  1460.                 operand.  If you want to specify a minimum field width, you
  1461.                 can do so using the "n" format option.  A format item of the
  1462.                 format "%10d" prints a decimal integer using at least ten
  1463.                 print positions.  Likewise, "%16s" prints a string using at
  1464.                 least 16 print positions.  If the value to print requires
  1465.                 more than the specified number of print positions, printf
  1466.                 will use however many are necessary.  If the value to print
  1467.                 requires fewer, printf will always print the specified number,
  1468.                 padding the value with blanks.  Printf will print the value
  1469.                 right justified in the print field (regardless of the data's
  1470.                 type).  If you want to print the value left justified in the
  1471.                 output file, use the "-" format character as a prefix to the
  1472.                 field width, e.g.,
  1473.  
  1474.                 printf
  1475.                 db      "%-17s",0
  1476.                 dd      string
  1477.  
  1478.                 In this example, printf prints the string using a 17 character
  1479.                 long field with the string left justified in the output field.
  1480.                 By default, printf blank fills the output field if the value
  1481.                 to print requires fewer print positions than specified by the
  1482.                 format item.  The "\c" format item allows you to change the
  1483.                 padding character.  For example, to print a value, right
  1484.                 justified, using "*" as the padding character you would use
  1485.                 the format item "%\*10d".  To print it left justified you
  1486.                 would use the format item "%-\*10d".  Note that the "-" must
  1487.                 precede the "\*".  This is a limitation of the current
  1488.                 version of the software.  The operands must appear in this
  1489.                 order.  Normally, the address(es) following the printf
  1490.                 format string must be far pointers to the actual data to print.
  1491.                 On occasion, especially when allocating storage on the heap
  1492.                 (using malloc), you may not know (at assembly time) the
  1493.                 address of the object you want to print.  You may have only
  1494.                 a pointer to the data you want to print.  The "^" format
  1495.                 option tells printf that the far pointer following the format
  1496.                 string is the address of a pointer to the data rather than
  1497.                 the address of the data itself.  This option lets you access
  1498.                 the data indirectly.
  1499.  
  1500.                 Note: unlike C, stdlib's printf routine does not support
  1501.                 floating point output.  Putting floating point into printf
  1502.         would increase the size of this routine a tremendous amount.
  1503.         Since most people don't need the floating point output
  1504.         facilities, it doesn't appear here.  Check out PRINTFF.
  1505.  
  1506. Include:        stdlib.a
  1507.  
  1508.  
  1509.  
  1510. Conversion Routines
  1511. -------------------
  1512.  
  1513.  
  1514. The stdlib conversion routines follow a uniform format of storing the data
  1515. to be converted and returned.  Most routines accept input and return data
  1516. of either an ASCII string of characters, stored in the ES:DI register, or
  1517. integers, stored in the DX:AX register.  If a value is just a 16 or 8-bit
  1518. value then it will be stored in AX or AL.
  1519.  
  1520. Since there is a possibility of an error in the input values to be converted,
  1521. such as it does not contain a proper value to convert, we use the
  1522. carry flag to show error status.  If the error flag is set then an error has
  1523. occured and things are okay if the carry flag is clear.
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529. Routine:  ATOL (2)
  1530. ------------------
  1531.  
  1532.  
  1533. Category:             Conversion Routine
  1534.  
  1535. Registers on Entry:   ES:DI- Points at string to convert
  1536.  
  1537. Registers on Return:  DX:AX- Long integer converted from string
  1538.               ES:DI- Points at first non-digit (ATOL2 only)
  1539.  
  1540. Flags Affected:       Carry flag- Error status
  1541.  
  1542. Examples of Usage:
  1543.               gets         ;Get a string from user
  1544.               ATOL         ;Convert to a value in DX:AX
  1545.  
  1546.  
  1547. Description:  ATOL converts the string of digits that ES:DI points at to a
  1548.           long (signed) integer value and returns this value in DX:AX.
  1549.           Note that the routine stops on the first non-digit.
  1550.           If the string does not begin with a digit, this routine returns
  1551.           zero.  The only exception to the "string of digits" only rule is
  1552.           that the number can have a preceding minus sign to denote a
  1553.           negative number.  Note that this routine does not allow leading
  1554.           spaces.  ATOL2 works in a similar fashion except it doesn't
  1555.           preserve the DI register.  That is, ATOL2 leaves DI pointing at
  1556.           the first character beyond the string of digits.  ATOL/ATOL2 both
  1557.           return the carry flag clear if it  translated the string of
  1558.           digits without error.  It returns the carry flag set if overflow
  1559.           occurred.
  1560.  
  1561.  
  1562. Include:                  stdlib.a
  1563.  
  1564.  
  1565.  
  1566. Routine:  AtoUL (2)
  1567. -------------------
  1568.  
  1569. Category:            Conversion Routine
  1570.  
  1571. Register on entry:   ES:DI- address of the string to be converted
  1572.  
  1573. Register on return:  DX:AX- 32-bit unsigned integer
  1574.              ES:DI- Points at first character beyond digits (ATOUL2
  1575.                 only)
  1576.  
  1577. Flags affected:      Carry flag- Set if error, clear if okay.
  1578.  
  1579. Examples of Usage:
  1580.              les InputString
  1581.              AtoUL
  1582.  
  1583.  
  1584. Description:  AtoUL converts the string pointed by ES:DI to a 32-bit unsigned
  1585.           integer.  It places the 32-bit unsigned integer into the memory
  1586.           address pointed by DX:AX. If there is an error in conversion,
  1587.           the carry flag will set to one. If there is not an error, the
  1588.           carry flag will be set to zero.
  1589.  
  1590.           ATOUL2 does not preserve DI.  It returns with DI pointing at
  1591.           the first non-digit character in the string.
  1592.  
  1593. Include:        stdlib.a
  1594.  
  1595.  
  1596.  
  1597. Routine:    ATOU (2)
  1598. --------------------
  1599.  
  1600. Category:            Conversion Routine
  1601.  
  1602. Register on entry:   ES:DI points at string to convert
  1603.  
  1604. Register on return:  AX-    unsigned 16-bit integer
  1605.              ES:DI- points at first non-digit (ATOU2 only)
  1606.  
  1607. Flags affected:      carry flag - error status
  1608.  
  1609. Example of Usage:
  1610.  
  1611. Description:    ATOU converts an ASCII string of digits, pointed to by ES:DI,
  1612.         to unsigned integer format. It places the unsigned 16-bit
  1613.         integer, converted from the string, into the AX register.
  1614.         ATOI works the same, except it handle unsigned 16-bit integers
  1615.         in the range 0..65535.
  1616.  
  1617.         ATOU2 leaves DI pointing at the first non-digit in the string.
  1618.  
  1619. Include:        stdlib.a
  1620.  
  1621.  
  1622.  
  1623. Routine: ATOH (2)
  1624. -----------------
  1625.  
  1626. Category:             Conversion Routine
  1627.  
  1628. Registers on Entry:   ES:DI- Points to string to convert
  1629.  
  1630. Registers on Return:  AX- Unsigned 16-bit integer converted from hex string
  1631.               DI (ATOH2)- First character beyond string of hex digits
  1632.  
  1633. Flags Affected:       Carry = Error status
  1634.  
  1635. Example of Usage:
  1636.               les  DI, Str2Convrt
  1637.               atoh                  ;Convert to value in AX.
  1638.               putw                  ;Print word in AX.
  1639.  
  1640.  
  1641. Description:  ATOH converts a string of hexadecimal digits, pointed to by
  1642.           ES:DI, into unsigned 16-bit numeric form. It returns the value in
  1643.           the AX register.  If there is an error in conversion, the carry
  1644.           flag will set to one.  If there is not an error, the carry flag
  1645.           will be clear.  ATOH2 works the same except it leaves DI
  1646.           pointing at the first character beyond the string of hex digits.
  1647.  
  1648. Include:        stdlib.a
  1649.  
  1650.  
  1651. Routine: ATOLH (2)
  1652. ------------------
  1653.  
  1654. Category:             Conversion Routine
  1655.  
  1656. Registers on Entry:   ES:DI- Points to string to convert
  1657.  
  1658. Registers on Return:  DX:AX- Unsigned 32-bit integer converted from hex string
  1659.               DI (ATOLH2)- First character beyond string of hex digits
  1660.  
  1661. Flags Affected:       Carry = Error status
  1662.  
  1663. Example of Usage:
  1664.               les  DI, Str2Convrt
  1665.               atolh                 ;Convert to value in DX:AX
  1666.  
  1667. Description:  ATOLH converts a string of hexadecimal digits, pointed to by
  1668.           ES:DI, into unsigned 32-bit numeric form. It returns the value in
  1669.           the DX:AX register.  If there is an error in conversion, the carry
  1670.           flag will set to one.  If there is not an error, the carry flag
  1671.           will be clear.  ATOLH2 works the same except it leaves the DI
  1672.           register pointing at the first non-hex digit.
  1673.  
  1674.  
  1675. Include:        stdlib.a
  1676.  
  1677.  
  1678.  
  1679. Routine:   ATOI (2)
  1680. -------------------
  1681.  
  1682. Category:             Conversion Routine
  1683.  
  1684. Register on entry:    ES:DI- Points at string to convert.
  1685.  
  1686. Register on return:   AX- Integer converted from string.
  1687.               DI (ATOI2)- First character beyond string of digits.
  1688.  
  1689. Flags affected:       Error status
  1690.  
  1691. Examples of Usage:
  1692.               les  DI, Str2Convrt
  1693.               atoi                 ;Convert to value in AX
  1694.  
  1695.  
  1696. Description:   Works just like ATOL except it translates the string to a
  1697.            signed 16-bit integer rather than a 32-bit long integer.
  1698.  
  1699.  
  1700. Include:              stdlib.a
  1701.  
  1702.  
  1703. Routine ITOA (2,M)
  1704. ------------------
  1705.  
  1706. Category:             Conversion Routine
  1707.  
  1708. Registers on Entry:   AX- Signed 16-bit value to convert to a string
  1709.               ES:DI- Pointer to buffer to hold result (ITOA/ITOA2
  1710.                  only).
  1711.  
  1712. Registers on Return:  ES:DI- Pointer to string containing converted
  1713.               characters (ITOA/ITOAM only).
  1714.               ES:DI- Pointer to zero-terminating byte of converted
  1715.                  string (ITOA2 only).
  1716.  
  1717. Flags Affected:       Carry flag is set on memory allocation error (ITOAM only)
  1718.  
  1719. Examples of Usage:
  1720.               mov     ax, -1234
  1721.               ITOAM                   ;Convert to string.
  1722.               puts                    ;Print it.
  1723.               free                    ;Deallocate string.
  1724.  
  1725.               mov     di, seg buffer
  1726.               mov     es, di
  1727.               lea     di, buffer
  1728.               mov     ax, -1234
  1729.               ITOA              ;Leaves string in BUFFER.
  1730.  
  1731.               mov     di, seg buffer
  1732.               mov     es, di
  1733.               lea     di, buffer
  1734.               mov     ax, -1234
  1735.               ITOA2              ;Leaves string in BUFFER and
  1736.                           ;ES:DI pointing at end of string.
  1737.  
  1738.  
  1739. Description:    These routines convert an integer value to a string of
  1740.         characters which represent that integer.  AX contains the
  1741.         signed integer you wish to convert.
  1742.  
  1743.         ITOAM automatically allocates storage on the heap for the
  1744.         resulting string, you do not have to pre-allocate this
  1745.         storage.  ITOAM returns a pointer to the (zero-terminated)
  1746.         string in the ES:DI registers.  It ignores the values in
  1747.         ES:DI on input.
  1748.  
  1749.         ITOA requires that the caller allocate the storage for the
  1750.         string (maximum you will need is seven bytes) and pass a
  1751.         pointer to this buffer in ES:DI.  ITOA returns with ES:DI
  1752.         pointing at the beginning of the converted string.
  1753.  
  1754.         ITOA2 also requires that you pass in the address of a buffer
  1755.         in the ES:DI register pair.  However, it returns with ES:DI
  1756.         pointing at the zero-terminating byte of the string.  This
  1757.         lets you easily build up longer strings via multiple calls
  1758.         to routines like ITOA2.
  1759.  
  1760. Include:        stdlib.a
  1761.  
  1762.  
  1763.  
  1764. Routine:   UTOA (2,M)
  1765. ---------------------
  1766.  
  1767. Category:            Conversion Routine
  1768.  
  1769. Registers on entry:   AX - unsigned 16-bit integer to convert to a string
  1770.               ES:DI- Pointer to buffer to hold result (UTOA/UTOA2
  1771.                  only).
  1772.  
  1773. Registers on Return:  ES:DI- Pointer to string containing converted
  1774.               characters (UTOA/UTOAM only).
  1775.               ES:DI- Pointer to zero-terminating byte of converted
  1776.                  string (UTOA2 only).
  1777.  
  1778. Flags affected:       Carry set denotes malloc error (UTOAM only)
  1779.  
  1780. Example of Usage:
  1781.               mov     ax, 65000
  1782.               utoa
  1783.               puts
  1784.               free
  1785.  
  1786.               mov     di, seg buffer
  1787.               mov     es, di
  1788.               lea     di, buffer
  1789.               mov     ax, -1234
  1790.               ITOA              ;Leaves string in BUFFER.
  1791.  
  1792.               mov     di, seg buffer
  1793.               mov     es, di
  1794.               lea     di, buffer
  1795.               mov     ax, -1234
  1796.               ITOA2              ;Leaves string in BUFFER and
  1797.                           ;ES:DI pointing at end of string.
  1798.  
  1799.  
  1800. Description:    UTOAx converts a 16-bit unsigned integer value in AX to a
  1801.         string of characters which represents that value.  UTOA,
  1802.         UTOA2, and UTOAM behave in a manner analogous to ITOAx.  See
  1803.         the description of those routines for more details.
  1804.  
  1805.  
  1806. Include:       stdlib.a
  1807.  
  1808.  
  1809.  
  1810. Routine:   HTOA (2,M)
  1811. ---------------------
  1812.  
  1813. Category:            Conversion Routine
  1814.  
  1815. Registers on entry:   AL - 8-bit integer to convert to a string
  1816.               ES:DI- Pointer to buffer to hold result (HTOA/HTOA2
  1817.                  only).
  1818.  
  1819. Registers on Return:  ES:DI- Pointer to string containing converted
  1820.               characters (HTOA/HTOAM only).
  1821.               ES:DI- Pointer to zero-terminating byte of converted
  1822.                  string (HTOA2 only).
  1823.  
  1824. Flags affected:      Carry set denotes memory allocation error (HTOAM only)
  1825.  
  1826.  
  1827. Description:    The HTOAx routines convert an 8-bit value in AL to the two-
  1828.         character hexadecimal representation of that byte.  Other
  1829.         that that, they behave just like ITOAx/UTOAx.  Note that
  1830.         the resulting buffer must have at least three bytes for
  1831.         HTOA/HTOA2.
  1832.  
  1833.  
  1834. Include:        stdlib.a
  1835.  
  1836.  
  1837. Routine:  WTOA (2,M)
  1838. --------------------
  1839.  
  1840. Category:             Conversion Routine
  1841.  
  1842. Registers on Entry:   AX- 16-bit value to convert to a string
  1843.               ES:DI- Pointer to buffer to hold result (WTOA/WTOA2
  1844.                  only).
  1845.  
  1846. Registers on Return:  ES:DI- Pointer to string containing converted
  1847.               characters (WTOA/WTOAM only).
  1848.               ES:DI- Pointer to zero-terminating byte of converted
  1849.                  string (WTOA2 only).
  1850.  
  1851. Flags Affected:       Carry set denotes memory allocation error (WTOAM only)
  1852.  
  1853. Example of Usage:
  1854.               Like WTOA above
  1855.  
  1856.  
  1857. Description:  WTOAx converts the 16-bit value in AX to a string of four
  1858.           hexadecimal digits. It behaves exactly like HTOAx except
  1859.           it outputs four characters (and requires a five byte buffer).
  1860.  
  1861.  
  1862. Include:        stdlib.a
  1863.  
  1864.  
  1865.  
  1866. Routine:  LTOA (2,M)
  1867. --------------------
  1868.  
  1869. Category:             Conversion Routine
  1870.  
  1871. Registers on entry:   DX:AX (contains a signed 32 bit integer)
  1872.               ES:DI- Pointer to buffer to hold result (LTOA/LTOA2
  1873.                  only).
  1874.  
  1875. Registers on Return:  ES:DI- Pointer to string containing converted
  1876.               characters (LTOA/LTOAM only).
  1877.               ES:DI- Pointer to zero-terminating byte of converted
  1878.                  string (LTOA2 only).
  1879.  
  1880. Flags affected:       Carry set if memory allocation error (LTOAM only)
  1881.  
  1882.  
  1883. Example of Usage: 
  1884.             mov    di, seg buffer    ;Get address of storage
  1885.             mov    es, di        ; buffer.
  1886.             lea    di, buffer
  1887.             mov    ax, word ptr value
  1888.             mov    dx, word ptr value+2
  1889.             ltoa
  1890.  
  1891. Description:    LtoA converts the 32-bit signed integer in DX:AX to a string
  1892.         of characters.  LTOA stores the string at the address specified
  1893.         in ES:DI (there must be at least twelve bytes available at
  1894.         this address) and returns with ES:DI pointing at this buffer.
  1895.         LTOA2 works the same way, except it returns with ES:DI
  1896.         pointing at the zero terminating byte.  LTOAM allocates
  1897.         storage for the string on the heap and returns a pointer
  1898.         to the string in ES:DI.
  1899.  
  1900. Include:        stdlib.a
  1901.  
  1902.  
  1903.  
  1904. Routine:  ULTOA (2,M)
  1905. ---------------------
  1906.  
  1907. Category:             Conversion Routine
  1908.  
  1909. Registers on Entry:   DX:AX- Unsigned 32-bit value to convert to a string
  1910.               ES:DI- Pointer to buffer to hold result (LTOA/LTOA2
  1911.                  only).
  1912. Registers on Return:  ES:DI- Pointer to string containing converted
  1913.               characters (LTOA/LTOAM only).
  1914.               ES:DI- Pointer to zero-terminating byte of converted
  1915.                  string (LTOA2 only).
  1916.  
  1917. Flags Affected:       Carry is set if malloc error (ULTOAM only)
  1918.  
  1919. Example of Usage:  
  1920.                       Like LTOA
  1921.  
  1922.  
  1923. Description:  Like LTOA except this routine handles unsigned integer values.
  1924.  
  1925. Include:    stdlib.a
  1926.  
  1927.  
  1928.  
  1929. Routine:  SPrintf (2,M)
  1930. -----------------------
  1931.  
  1932. Category:            Conversion Routine
  1933.              In-Memory Formatting Routine
  1934.  
  1935. Registers on entry:  CS:RET - Pointer to format string and operands of the
  1936.                   sprintf routine
  1937.              ES:DI-   Address of buffer to hold output string
  1938.                   (sprintf/sprintf2 only)
  1939.  
  1940. Register on return:  ES:DI register - pointer to a string containing
  1941.                       output data (sprintf/sprintfm only).
  1942.                       Pointer to zero-terminating byte at the
  1943.                       end of the converted string (sprintf2
  1944.                       only).
  1945.  
  1946. Flags affected:      Carry is set if memory allocation error (sprintfm only).
  1947.  
  1948. Example of Usage:
  1949.              sprintfm
  1950.              db      "I=%i, U=%u, S=%s",13,10,0
  1951.              db      i,u,s
  1952.              puts
  1953.              free
  1954.  
  1955.  
  1956. Description:   SPrintf is an in-memory formatting routine. It is similar to
  1957.            C's sprintf routine.
  1958.  
  1959.            The programmer selects the maximum length of the output string.
  1960.            SPrintf works in a manner quite similar to printf, except sprintf
  1961.            writes its output to a string variable rather than to the stdlib
  1962.            standard output.
  1963.  
  1964.            SPrintfm, by default, allocates 2048 characters for the string
  1965.            and then deallocates any unnecessary storage.  An external
  1966.            variable, sp_MaxBuf, holds the number of bytes to allocate upon
  1967.            entry into sprintfm.  If you wish to allocate more or less than
  1968.            2048 bytes when calling sprintf, simply change the value of this
  1969.            public variable (type is word).  Sprintfm calls malloc to
  1970.            allocate the storage dynamically.  You should call free to
  1971.            return this buffer to the heap when you are through with it.
  1972.  
  1973.            Sprintf and Sprintf2 expect you to pass the address of a buffer
  1974.            to them.  You are responsible for supplying a sufficiently
  1975.            sized buffer to hold the result.
  1976.  
  1977. Include:             stdlib.a
  1978.  
  1979.  
  1980.  
  1981. Routine:  SScanf
  1982. ----------------
  1983.  
  1984. Category:              Conversion Routine
  1985.                Formatted In-Memory Conversion Routine
  1986.  
  1987. Registers on Entry:    ES:DI - points at string containing values to convert
  1988.  
  1989. Registers on return:   None
  1990.  
  1991. Flags affected:           None
  1992.  
  1993. Example of Usage:
  1994.  
  1995.           ; this code reads the values for i, j, and s from the characters
  1996.           ; starting at memory location Buffer.
  1997.  
  1998.                les   di, Buffer
  1999.                SScanf
  2000.                db    "%i %i %s",0
  2001.                dd     i, j, s
  2002.  
  2003.  
  2004. Description:  SScanf provides formatted input in a fashion analogous to scanf.
  2005.               The difference is that scanf reads in a line of text from the
  2006.               stdlib standard input whereas you pass the address of a sequence
  2007.               of characters to SScanf in es:di.
  2008.  
  2009.  
  2010. Include:                stdlib.a
  2011.  
  2012.  
  2013.  
  2014.  
  2015. Routine:  ToLower
  2016. -----------------
  2017.  
  2018. Category:            Conversion Routine
  2019.  
  2020. Register on entry:   AL- Character to (possibly) convert
  2021.                 to lower case.
  2022.  
  2023. Register on return:  AL- Converted character.
  2024.  
  2025. Flags affected:      None
  2026.  
  2027. Example of usage:
  2028.              mov     al, char
  2029.              ToLower
  2030.  
  2031.  
  2032. Description:  ToLower checks the character in the AL register, if it is upper
  2033.           case it converts it to lower case.  If it is anything else,
  2034.           ToLower leaves the value in AL unchanged.  For high performance
  2035.           this routine is implemented as a macro rather than as a
  2036.           procedure call.  This routine is so short you would spend more
  2037.           time actually calling the routine than executing the code inside.
  2038.           However, the code is definitely longer than a (far) procedure
  2039.           call, so if space is critical and you're invoking this code
  2040.           several times, you may want to convert it to a procedure call to
  2041.           save a little space.
  2042.  
  2043.  
  2044. Include:             stdlib.a
  2045.  
  2046.  
  2047.  
  2048. Routine:   ToUpper
  2049. ------------------
  2050.  
  2051. Category:             Conversion Routine
  2052.  
  2053. Registers on Entry:   AL- Character to (possibly) convert to upper case
  2054.  
  2055. Registers on Return:  AL- Converted character
  2056.  
  2057. Flags Affected:       None
  2058.  
  2059. Example of Usage:
  2060.               mov  al, char
  2061.               ToUpper
  2062.  
  2063.  
  2064. Description:  ToUpper checks the character in the AL register, if it is lower
  2065.           case it converts it to upper case.  If it is anything else,
  2066.           ToUpper leaves the value in AL unchanged.  For high performance
  2067.           this routine is implemented as a macro rather than as a
  2068.           procedure call (see ToLower, above).
  2069.  
  2070.  
  2071. Include:              stdlib.a
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077. Utility Routines
  2078. ----------------
  2079.  
  2080. The following 10 routines are all Utility Routines.  The first routines listed
  2081. below compute the number of print positions required by a 16-bit and 32-bit
  2082. signed and unsigned integer value.  UlSize is like the LSize except it treats
  2083. the value in DX:AX as an unsigned long integer.  The next set of routines in
  2084. this section check the character in the AL register to see whether it is a
  2085. hexidecimal digit, if it alphabetic, if it is a lower case alphabetic, if it
  2086. is a upper case alphabetic, and if it is numeric.
  2087.  
  2088.  
  2089.  
  2090.  
  2091. Routine:  ISize
  2092. ---------------
  2093.  
  2094. Category:            Utility Routine
  2095.  
  2096. Register on entry:   AX- 16-bit value to compute the
  2097.                 output size for.
  2098.  
  2099. Register on return:  AX- Number of print positions
  2100.                 required by this number (including
  2101.                 the minus sign, if necessary).
  2102.  
  2103. Flags affected:      None
  2104.  
  2105. Example of usage:
  2106.              mov     ax, I
  2107.              ISize
  2108.              puti                    ;Prints positions
  2109.                          ;req'd by I.
  2110.  
  2111.  
  2112. Description:         This routine computes the number of print positions
  2113.              required by a 16-bit signed integer value.  ISize computes
  2114.              the minimum number of character positions it takes to print
  2115.              the signed decimal value in the AX register.  If the number
  2116.              is negative, it will include space for the minus sign in
  2117.              the count.
  2118.  
  2119.  
  2120. Include:             stdlib.a
  2121.  
  2122.  
  2123.  
  2124.  
  2125. Routine:  USize
  2126. ---------------
  2127.  
  2128. Category:            Utility Routine
  2129.  
  2130. Register on entry:   AX- 16 bit value to compute the
  2131.                 output size for
  2132.  
  2133. Register on return:  AX- number of print positions
  2134.              required by this number (including
  2135.              the minus sign, if necessary)
  2136.  
  2137. Flags affected:      None
  2138.  
  2139. Example of usage:
  2140.              mov     ax, I
  2141.              USize
  2142.              puti                    ;prints position
  2143.                          ;required by I
  2144.  
  2145.  
  2146. Description:         This routine computes the number of print positions
  2147.              required by a 16-bit signed integer value.  It also
  2148.              computes the number of print positions required by a
  2149.              16-bit unsigned value.  USize computes the minimum number
  2150.              of character positions it will take to print an unsigned
  2151.              decimal value in the AX register.  If the number is
  2152.              negative, it will include space for the minus sign in the
  2153.              count.
  2154.  
  2155.  
  2156. Include:             stdlib.a
  2157.  
  2158.  
  2159. Routine:  LSize
  2160. ---------------
  2161.  
  2162. Category:            Utility Routine
  2163.  
  2164. Register on entry:   DX:AX   - 32-bit value to compute the
  2165.                    output size for.
  2166.  
  2167. Register on return:  AX - Number of print positions
  2168.               required by this number (including
  2169.               the minus sign, if necessary).
  2170.  
  2171. Flags affected:      None
  2172.  
  2173. Example of Usage:
  2174.              mov     ax, word ptr L
  2175.              mov     dx, word ptr L+2
  2176.              LSize
  2177.              puti                    ;Prints positions
  2178.                          ;req'd by L.
  2179.  
  2180.  
  2181. Description:         This routine computes the number of print positions
  2182.              required by a 32-bit signed integer value.  LSize computes
  2183.              the minimum number of character positions it will take to
  2184.              print the signed decimal value in the DX:AX registers.  If
  2185.              the number is negative, it will include space for the minus
  2186.              sign in the count.
  2187.  
  2188.  
  2189. Include:             stdlib.a
  2190.  
  2191.  
  2192.  
  2193. Routine:  ULSize
  2194. ----------------
  2195.  
  2196. Category:             Utility Routine
  2197.  
  2198. Registers on Entry:   DX:AX - 32-bit value to compute the output size for.
  2199.  
  2200. Registers on return:  AX - number of print positions required by this number
  2201.  
  2202. Flags affected:       None
  2203.  
  2204. Example of Usage:
  2205.               mov     ax, word ptr L
  2206.               mov     dx, word ptr L+2
  2207.               ULSize
  2208.               puti                    ; Prints positions req'd by L
  2209.  
  2210.  
  2211. Description:          ULSize computes the minimum number of character
  2212.               positions it will take to print an unsigned decimal
  2213.               value in the DX:AX registers.
  2214.  
  2215.  
  2216. Include:              stdlib.a
  2217.  
  2218.  
  2219.  
  2220. Routine:  IsAlNum
  2221. -----------------
  2222.  
  2223. Category:             Utility routine
  2224.  
  2225. Register on entry:    AL - character to check.
  2226.  
  2227. Register on return:   None
  2228.  
  2229. Flags affected:       Zero flag - set if character is alphanumeric,
  2230.               clear if not.
  2231.  
  2232.  
  2233. Example of usage :    mov al, char
  2234.               IsAlNum
  2235.               je IsAlNumChar
  2236.  
  2237.  
  2238. Description :         This routine checks the character in the AL register to
  2239.               see if it is in the range A-Z, a-z, or 0-9.  Upon return,
  2240.               you can use the JE instruction to check to see if the
  2241.               character was in this range (or, conversely, you can use
  2242.               JNE to see if it is not in range).
  2243.  
  2244.  
  2245. Include:              stdlib.a
  2246.  
  2247.  
  2248. Routine:  IsXDigit
  2249. ------------------
  2250.  
  2251. Category:               Utility Routine
  2252.  
  2253. Register on Entry:     AL- character to check
  2254.  
  2255. Registers on Return:    None
  2256.  
  2257. Flags Affected:         Zero flag-  Set if character is a hex digit, clear if not
  2258.  
  2259.  
  2260. Example of Usage:       mov    al, char
  2261.             IsXDigit
  2262.             je     IsXDigitChar
  2263.  
  2264.  
  2265. Description:            This routine checks the character in the AL register to
  2266.             see if it is in the range A-F, a-f, or 0-9.  Upon
  2267.             return, you can use the JE instruction to check to see
  2268.             if the character was in this range (or, conversely,
  2269.             you can use jne to see if it is not in the range).
  2270.  
  2271.  
  2272. Include:                stdlib.a
  2273.  
  2274.  
  2275. Routine:   IsDigit
  2276. ------------------
  2277.  
  2278. Category:            Utility Routine
  2279.  
  2280. Register on entry:   AL- Character to check
  2281.  
  2282. Register on return:  None
  2283.  
  2284. Flags affected:         Zero flag- set if character is numeric, clear if not.
  2285.  
  2286. Example of Usage:    mov   al, char
  2287.              IsDigit
  2288.              je  IsDecChar
  2289.  
  2290.  
  2291. Description:         This routine checks the character in the AL register to
  2292.              see if it is in the range 0-9.  Upon return, you can use
  2293.              the JE instruction to check to see if the character was
  2294.              in the range (or, conversely, you can use JNE to see if it
  2295.              is not in the range).
  2296.  
  2297.  
  2298. Include:             stdlib.a
  2299.  
  2300.  
  2301. Routine:   IsAlpha
  2302. ------------------
  2303.  
  2304. Category:            Utility Routine
  2305.  
  2306. Register on entry:   AL- Character to check
  2307.  
  2308. Register on return:  None
  2309.  
  2310. Flags affected:         Zero flag- set if character is alphabetic, clear if not.
  2311.  
  2312. Example of Usage:    mov   al, char
  2313.              IsAlpha
  2314.              je   IsAlChar
  2315.  
  2316.  
  2317. Description:         This routine checks the character in the AL register to
  2318.              see if it is in the range A-Z or a-z.  Upon return, you
  2319.              can use the JE instruction to check to see if the character
  2320.              was in the range (or, conversely, you can use JNE to see
  2321.              if it is not in the range).
  2322.  
  2323. Include:             stdlib.a
  2324.  
  2325.  
  2326.  
  2327.  
  2328. Routine: IsLower
  2329. ----------------
  2330.  
  2331. Category:             Utility Routine
  2332.  
  2333. Registers on Entry:   AL- character to test
  2334.  
  2335. Registers on Return:  None
  2336.  
  2337.  
  2338. Flags Affected:       Zero = 1 if character is a lower case alphabetic character
  2339.               Zero = 0 if character is not a lower case alphabetic
  2340.               character
  2341.  
  2342. Example of Usage:     mov  AL, char        ; put char in AL
  2343.               IsLower              ; is char lower a-z?
  2344.               je  IsLowerChar      ; if yes, jump to IsLowerChar
  2345.  
  2346.  
  2347. Description:          This routine checks the character in the AL register to
  2348.               see if it is in the range a-z.  Upon return, you can use
  2349.               the JE instruction to check and see if the character was
  2350.               in this range (or you can use JNE to check and see if
  2351.               the character was not in this range).  This procedure is
  2352.               implemented as a macro for high performance.
  2353.  
  2354.  
  2355. Include:              stdlib.a
  2356.  
  2357.  
  2358. Routine:  IsUpper
  2359. -----------------
  2360.  
  2361. Category:             Utility Routine
  2362.  
  2363. Registers on Entry:   AL- character to check
  2364.  
  2365. Registers on Return:  None
  2366.  
  2367. Flags Affected:       Zero flag - set if character is uppercase alpha, clear
  2368.                   if not.
  2369.  
  2370.  
  2371. Example of Usage:     mov al, char
  2372.               IsUpper
  2373.               je IsUpperChar
  2374.  
  2375.  
  2376. Description:          This routine checks the character in the AL register to
  2377.               see if it is in the ranger A-Z.  Upon return, you can use
  2378.               the JE instruction to check to see if it not in the
  2379.               range).  It uses macro implementation for high performance.
  2380.  
  2381.  
  2382. Include:              stdlib.a
  2383.  
  2384.  
  2385.  
  2386. String Handling Routines
  2387. ------------------------
  2388.  
  2389. Manipulating text is a major part of many computer applications. Typically,
  2390. strings are inputed and interpreted. This interpretation may involve some
  2391. chores such as extracting certain part of the text, copying it, or comparing
  2392. with other strings.
  2393.  
  2394. The string manipulation routines in C provides various functions. Therefore,
  2395. the stdlib has some C-like string handling functions (e.g. strcpy, strcmp).
  2396. In C a string is an array of characters; similarly, the string are terminated
  2397. by a "0" as a null character. In general, the input strings of these routines
  2398. are pointed by ES:DI. In some routines, the carry flag will be set to indicate
  2399. an error.
  2400.  
  2401. The following string routines take as many as four different forms: strxxx,
  2402. strxxxl, strxxxm, and strxxxlm.  These routines differ in how they store
  2403. the destination string into memory and where they obtain their source strings.
  2404.  
  2405. Routines of the form strxxx generally expect a single source string address
  2406. in ES:DI or a source and destination string in ES:DI & DX:SI.  If these
  2407. routines produce a string, they generally store the result into the buffer
  2408. pointed at by ES:DI upon entry.  They return with ES:DI pointing at the
  2409. first character of the destination string.
  2410.  
  2411. Routines of the form strxxxl have a "literal source string".  A literal
  2412. source string follows the call to the routine in the code stream.  E.g.,
  2413.  
  2414.             strcatl
  2415.             db    "Add this string to ES:DI",0
  2416.  
  2417. Routines of the form strxxxm automatically allocate storage for a source
  2418. string on the heap and return a pointer to this string in ES:DI.
  2419.  
  2420. Routines of the form strxxxlm have a literal source string in the code
  2421. stream and allocate storage for the destination string on the heap.
  2422.  
  2423.  
  2424.  
  2425. Routine:  Strcpy (l)
  2426. --------------------
  2427.  
  2428. Category:             String Handling Routine
  2429.  
  2430. Registers on Entry:   ES:DI - pointer to source string (Strcpy only)
  2431.               CS:RET - pointer to  source  string (Strcpy1 only)
  2432.               DX:SI - pointer to destination string
  2433.  
  2434.  
  2435. Registers on return:  ES:DI - points at the destination string
  2436.  
  2437.  
  2438. Flags affected:          None
  2439.  
  2440.  
  2441. Example of Usage:
  2442.               mov     dx, seg Dest
  2443.               mov     si, offset Dest
  2444.               mov     di, seg Source
  2445.               mov     es, di
  2446.               mov     si, offset Source
  2447.               Strcpy
  2448.  
  2449.               mov     dx, seg Dest
  2450.               mov     si, offset Dest
  2451.               Strcpyl
  2452.               db      "String to copy",0
  2453.  
  2454.  
  2455. Description:  Strcpy is used to copy a zero-terminated string from one
  2456.           location to another.  ES:DI points at the source string,
  2457.           DX:SI points at the destination address.  Strcpy copies all
  2458.           bytes, up to and including the zero byte, from the source
  2459.           address to the destination address.  The target buffer must
  2460.           be large enough to hold the string.  Strcpy performs no error
  2461.           checking on the size of the destination buffer.
  2462.  
  2463.           Strcpyl copies the  zero-terminated string immediately following
  2464.           the call instruction to the destination address specified by
  2465.           DX:SI.  Again, this routine expects you to ensure that the
  2466.           taraget buffer is large enough to hold the result.
  2467.  
  2468.           Note: There are no "Strcpym" or "Strcpylm" routines.  The
  2469.           reason is simple: "StrDup" and "StrDupl" provide these functions
  2470.           using names which are familiar to MSC and Borland C users.
  2471.  
  2472. Include:              stdlib.a
  2473.  
  2474.  
  2475. Routine:  StrDup (l)
  2476. --------------------
  2477.  
  2478. Category:            String Handling Routine
  2479.  
  2480. Register on entry:   ES:dI - pointer to source string (StrDup
  2481.              only).  CS:RET - Pointer to source string
  2482.              (StrDupl only).
  2483.  
  2484. Register on return:  ES:DI - Points at the destination string
  2485.              allocated on heap.  Carry=0 if operation
  2486.              successful.  Carry=0 if insufficient
  2487.              memory for new string.
  2488.  
  2489. Flags affected:      Carry flag
  2490.  
  2491. Example of usage:
  2492.              StrDupl
  2493.              db "String for StrDupl",0
  2494.              jc  MallocError
  2495.              mov word ptr Dest1, di
  2496.              mov word ptr Dest1+2, es  ;create another
  2497.                            ;copy of this
  2498.                            ;string. Note
  2499.                            ;that es:di points
  2500.                            ;at Dest1 upon
  2501.                            ;entry to StrDup,
  2502.                            ;but it points at
  2503.                            ;the new string on
  2504.                            ;exit
  2505.              StrDup
  2506.              jc MallocError
  2507.              mov word ptr Dest2, di
  2508.              mov word ptr Dest2+2, es
  2509.  
  2510.  
  2511. Description:  StrDup and StrDupl duplicate strings.  You pass them
  2512.           a pointer to the string (in es:di for strdup, via
  2513.           the return address for strdupl) and they allocate
  2514.           sufficient storage on the heap for a copy of this
  2515.           string.  Then these two routines copy their source
  2516.           strings to the newly allocated storage and return
  2517.           a pointer to the new string in ES:DI.
  2518.  
  2519.  
  2520. Include:             stdlib.a
  2521.  
  2522.  
  2523. Routine:  Strlen
  2524. ----------------
  2525.  
  2526. Category:            String Handling Routine
  2527.  
  2528. Registers on entry:  ES:DI - pointer to source string.
  2529.  
  2530. Register on return:  CX - length of specified string.
  2531.  
  2532. Flags Affected:      None
  2533.  
  2534. Examples of Usage:
  2535.              les   di, String
  2536.              strlen
  2537.              mov   sl, cx
  2538.              printf
  2539.              db   "Length of '%s' is %d\n",0
  2540.              dd   String, sl
  2541.  
  2542.  
  2543. Description:  Strlen computes the length of the string whose address
  2544.           appears in ES:DI.  It returns the number of characters
  2545.           up to, but not including, the zero terminating byte.
  2546.  
  2547. Include:             stdlib.a
  2548.  
  2549.  
  2550. Routine:  Strcat (m,l,ml)
  2551. -------------------------
  2552.  
  2553. Category:             String Handling Routine
  2554.  
  2555. Registers on Entry:   ES:DI- Pointer to first string
  2556.               DX:SI- Pointer to second string (Strcat and Strcatm only)
  2557.  
  2558.  
  2559. Registers on Return:  ES:DI- Pointer to new string (Strcatm and Strcatml only)
  2560.  
  2561. Flags Affected:       Carry = 0 if no error
  2562.               Carry = 1 if insufficient memory (Strcatm and Strcatml
  2563.                             only)
  2564.  
  2565.  
  2566. Example of Usage:     les  DI, String1
  2567.               mov  DX, seg String2
  2568.               lea  SI, String2
  2569.               Strcat                   ; String1 <- String1 + String2
  2570.  
  2571.               les  DI, String1
  2572.               Strcatl                  ; String1 <- String1 +
  2573.               db  "Appended String",0  ;            "Appended String",0
  2574.  
  2575.  
  2576.               les  DI, String1
  2577.               mov  DX, seg String2
  2578.               lea  SI, String2
  2579.               Strcatm                  ; NewString <- String1 + String2
  2580.               puts
  2581.               free
  2582.  
  2583.               les  DI, String1
  2584.               Strcatml                 ; NewString <- String1 +
  2585.               db  "Appended String",0  ;         "Appended String",0
  2586.               puts
  2587.               free
  2588.  
  2589.  
  2590. Description:  These routines concatenate two strings together.  They differ
  2591.           mainly in the location of their source and destination operands.
  2592.  
  2593.           Strcat concatenates the string pointed at by DX:SI to the end of
  2594.           the string pointed at by ES:DI in memory.  Both strings must be
  2595.           zero-terminated.  The buffer pointed at by ES:DI must be large
  2596.           enough to hold the resulting string.  Strcat does NOT perform
  2597.           bounds checking on the data.
  2598.  
  2599.           ( continued on next page )
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607. Routine:  Strcat (m,l,ml)   ( continued )
  2608. -----------------------------------------
  2609.  
  2610.  
  2611.           Strcatm computes the length of the two strings pointed at by ES:DI
  2612.           and DX:SI and attempts to allocate this much storage on the heap.
  2613.           If it is not successful, Strcatm returns with the Carry flag set,
  2614.           otherwise it copies the string pointed at by ES:DI to the heap,
  2615.           concatenates the string DX:SI points at to the end of this string
  2616.           on the heap, and returns with the Carry flag clear and ES:DI
  2617.           pointing at the new (concatenated) string on the heap.
  2618.  
  2619.           Strcatl and Strcatml work just like Strcat and Strcatm except you
  2620.           supply the second string as a literal constant immediately AFTER
  2621.           the call rather than pointing DX:SI at it (see examples above).
  2622.  
  2623.  
  2624. Include:             stdlib.a
  2625.  
  2626.  
  2627. Routine:  Strchr
  2628. ----------------
  2629.  
  2630. Category:            String Handling Routine
  2631.  
  2632. Register on entry:   ES:DI- Pointer to string.
  2633.             AL- Character to search for.
  2634.  
  2635. Register on return:  CX- Position (starting at zero)
  2636.              where Strchr found the character.
  2637.  
  2638. Flags affected:      Carry=0 if Strchr found the character.
  2639.              Carry=1 if the character was not present
  2640.                  in the string.
  2641.  
  2642. Example of usage:
  2643.              les di, String
  2644.              mov al, Char2Find
  2645.              Strchr
  2646.              jc  NotPresent
  2647.              mov CharPosn, cx
  2648.  
  2649.  
  2650. Description:  Strchr locates the first occurrence of a character within a
  2651.           string.  It searches through the zero-terminated string pointed
  2652.           at by es:di for the character passed in AL. If it locates the
  2653.           character, it returns the position of that character to the CX
  2654.           register.  The first character in the string corresponds to the
  2655.           location zero.  If the character is not in the string, Strchr
  2656.           returns the carry flag set.  CX's value is undefined in that
  2657.           case.  If Strchr locates the character in the string, it
  2658.           returns with the carry clear.
  2659.  
  2660.  
  2661. Include:             stdlib.a
  2662.  
  2663.  
  2664. Routine:  Strstr (l)
  2665. --------------------
  2666.  
  2667. Category:            String Handling Routine
  2668.  
  2669. Register on entry:   ES:DI - Pointer to string.
  2670.              DX:SI - Pointer to substring(strstr).
  2671.              CS:RET - Pointer to substring (strstrl).
  2672.  
  2673. Register on return:  CX - Position (starting at zero)
  2674.              where Strstr/Strstrl found the
  2675.              character.  Carry=0 if Strstr/
  2676.              Strstrl found the character.
  2677.              Carry=1 if the character was not
  2678.              present in the string.
  2679.  
  2680. Flags affected:      Carry flag
  2681.  
  2682. Example of usage :
  2683.              les di, MainString
  2684.              lea si, Substring
  2685.              mov dx, seg Substring
  2686.              Strstr
  2687.              jc NoMatch
  2688.              mov i, cx
  2689.              printf
  2690.              db "Found the substring '%s' at location %i\n",0
  2691.              dd Substring, i
  2692.  
  2693.  
  2694. Description:  Strstr searches for the position of a substring
  2695.           within another string.  ES:DI points at the
  2696.           string to search through, DX:SI points at the
  2697.           substring.  Strstr returns the index into ES:DI's
  2698.           string where DX:SI's string is found.  If the
  2699.           string is found, Strstr returns with the carry
  2700.           flag clear and CX contains the (zero based) index
  2701.           into the string.  If Strstr cannot locate the
  2702.           substring within the string ES:DI points at, it
  2703.           returns the carry flag set.  Strstrl works just
  2704.           like Strstr except it excepts the substring to
  2705.           search for immediately after the call instruction
  2706.           (rather than passing this address in DX:SI).
  2707.  
  2708.  
  2709. Include:              stdlib.a
  2710.  
  2711.  
  2712. Routine:  Strcmp (l)
  2713. --------------------
  2714.  
  2715. Category:            String Handling Routine
  2716.  
  2717. Registers on entry:  ES:DI contains the address of the first string
  2718.              DX:SI contains the address of the second string (strcmp)
  2719.              CS:RET (contains the address of the substring (strcmpl)
  2720.  
  2721. Register on return:  CX (contains the position where the two strings differ)
  2722.  
  2723. Flags affected:      Carry flag and zero flag (string1 > string2 if C + Z = 0)
  2724.                      (string1 < string2 if C = 1)
  2725.  
  2726. Example of Usage:
  2727.              les     di, String1
  2728.              mov     dx, seg String2
  2729.              lea     si, String2
  2730.              strcmp
  2731.              ja        OverThere
  2732.  
  2733.              les     di, String1
  2734.              strcmpl
  2735.              db     "Hello",0
  2736.              jbe     elsewhere
  2737.  
  2738.  
  2739.  
  2740. Description:  Strcmp compares the first strings pointed by ES:DI with
  2741.           the second string pointed by DX:SI. The carry and zero flag
  2742.           will contain the corresponding result. So unsigned branch
  2743.           instructions such as JA or JB is recommended. If string1
  2744.           equals string2, strcmp will return with CX containing the
  2745.           offset of the zero byte in the two strings.
  2746.  
  2747.           Strcmpl compares the first string pointed by ES:DI with
  2748.           the substring pointed by CS:RET. The carry and zero flag
  2749.           will contain the corresponding result. So unsigned branch
  2750.           instructions such as JA or JB are recommended. If string1
  2751.           equals to the substring, strcmp will return with CX
  2752.           containing the offset of the zero byte in the two strings.
  2753.  
  2754. Include:             stdlib.a
  2755.  
  2756.  
  2757. Routine:  Strupr (m)
  2758. --------------------
  2759.  
  2760. Category:            String Handling Routine
  2761.              Conversion Routine
  2762.  
  2763. Register on entry:   ES:DI (contains the pointer to input string)
  2764.  
  2765. Register on return:  ES:DI (contains the pointer to input string
  2766.                with characters converted to upper case)
  2767.                Note: struprm allocates storage for a new
  2768.                string on the heap and returns the pointer
  2769.                to this routine in ES:DI.
  2770.  
  2771. Flags affected:      Carry = 1 if memory allocation error (Struprm only).
  2772.  
  2773. Example of Usage:
  2774.              les     di, lwrstr1
  2775.              strupr
  2776.              puts
  2777.  
  2778.              mov        di, seg StrWLwr
  2779.              mov    es, di
  2780.              lea    di, StrWLwr
  2781.              struprm
  2782.              puts
  2783.              free
  2784.  
  2785.  
  2786. Description:  Strupr converts the input string pointed by ES:DI to
  2787.           upper case.  It will actually modify the string you pass
  2788.           to it.
  2789.  
  2790.           Struprm first makes a copy of the string on the heap and
  2791.           then converts the characters in this new string to upper
  2792.           case.  It returns a pointer to the new string in ES:DI.
  2793.  
  2794. Include:             stdlib.a
  2795.  
  2796.  
  2797. Routine:  Strlwr (m)
  2798. --------------------
  2799.  
  2800. Category:            String Handling Routine
  2801.              Conversion Routine
  2802.  
  2803. Register on entry:   ES:DI (contains the pointer to input string)
  2804.  
  2805. Register on return:  ES:DI (contains the pointer to input string
  2806.                with characters converted to lower case).
  2807.  
  2808. Flags affected:      Carry = 1 if memory allocation error (strlwrm only)
  2809.  
  2810.  
  2811. Example of Usage:
  2812.              les di, uprstr1
  2813.              strlwr
  2814.              puts
  2815.  
  2816.              mov        di, seg StrWLwr
  2817.              mov    es, di
  2818.              lea    di, StrWLwr
  2819.              strlwrm
  2820.              puts
  2821.              free
  2822.  
  2823.  
  2824.  
  2825.  
  2826. Description:  Strlwr converts the input string pointed by ES:DI to
  2827.           lower case. It will actually modify the string you pass
  2828.           to it.
  2829.  
  2830.           Strlwrm first copies the characters onto the heap and then
  2831.           returns a pointer to this string after converting all the
  2832.           alphabetic characters to lower case.
  2833.  
  2834.  
  2835. Include:             stdlib.a
  2836.  
  2837.  
  2838.  
  2839. Routine:  Strset (m)
  2840. --------------------
  2841.  
  2842. Category:            String Handling Routine
  2843.  
  2844. Register on entry:   ES:DI contains the pointer to input string (StrSet only)
  2845.              AL    contains the character to copy
  2846.              CX    contains number of characters to allocate for
  2847.                the string (Strsetm only)
  2848.  
  2849. Register on return:  ES:DI pointer to newly allocated string (Strsetm only)
  2850.  
  2851. Flags affected:      Carry set if memory allocation error (Strsetm only)
  2852.  
  2853. Example of Usage:
  2854.              les     di, string1
  2855.              mov    al, " "        ;Blank fill string.
  2856.              Strset
  2857.  
  2858.              mov     cx, 32
  2859.              mov    al, "*"        ;Create a new string w/32
  2860.              Strsetm            ; asterisks.
  2861.              puts
  2862.              free
  2863.  
  2864.  
  2865. Description:  Strset overwrites the data on input string pointed by
  2866.           ES:DI with the character on AL.
  2867.  
  2868.           Strsetm creates a new string on the heap with the number
  2869.           of characters specified in CX.  All characters in the string
  2870.           are initialized with the value in AL.
  2871.  
  2872. Include:             stdlib.a
  2873.  
  2874.  
  2875. Routine:  Strspan (l)
  2876. ---------------------
  2877.  
  2878. Category:             String Handling Routine
  2879.  
  2880. Registers on Entry:   ES:DI - Pointer to string to scan
  2881.               DX:SI - Pointer to character set (Strspan only)
  2882.               CS:RET- Pointer to character set (Strspanl only)
  2883.  
  2884. Registers on Return:  CX- First position in scanned string which does not
  2885.               contain one of the characters in the character set
  2886.  
  2887. Flags Affected:       None
  2888.  
  2889. Example of Usage:
  2890.               les  DI, String
  2891.               mov  DX, seg CharSet
  2892.               lea  SI, CharSet
  2893.               Strspan           ; find first position in String with a
  2894.               mov i, CX         ;                  char not in CharSet
  2895.               printf
  2896.               db  "The first char which is not in CharSet "
  2897.               db  "occurs at position %d in String.\n",0
  2898.               dd  i
  2899.  
  2900.               les  DI, String
  2901.               Strspanl          ; find first position in String which
  2902.               db   "aeiou",0    ; is not a vowel
  2903.               mov  j, CX
  2904.               printf
  2905.               db  "The first char which is not a vowel "
  2906.               db  "occurs at position %d in String.\n",0
  2907.               dd  j
  2908.  
  2909.  
  2910. Description:  Strspan(l) scans a string, counting the number of characters which
  2911.           are present in a second string (which represents a character set).
  2912.           ES:DI points at a zero-terminated string of characters to scan.
  2913.           DX:SI (strspan) or CS:RET (strspanl) points at another zero-
  2914.           terminated string containing the set of characters to compare
  2915.           against.  The position of the first character in the string
  2916.           pointed to by ES:DI which is NOT in the character set is returned.
  2917.           If all the characters in the string are in the character set, the
  2918.           position of the zero-terminating byte will be returned.
  2919.  
  2920.           Although strspan and (especially) strspanl are very compact and
  2921.           convenient to use, they are not particularly efficient.  The
  2922.           character set routines provide a much faster alternative at the
  2923.           expense of a little more space.
  2924.  
  2925.  
  2926. Include:               stdlib.a
  2927.  
  2928.  
  2929. Routine:  Strcspan, Strcspanl
  2930. -----------------------------
  2931.  
  2932. Category:             String Handling Routine
  2933.  
  2934. Registers on Entry:   ES:DI - Pointer to string to scan
  2935.               DX:SI - Pointer to character set (Strcspan only)
  2936.               CS:RET- Pointer to character set (Strcspanl only)
  2937.  
  2938. Registers on Return:  CX- First position in scanned string which contains one
  2939.               of the characters in the character set
  2940.  
  2941. Flags Affected:       None
  2942.  
  2943. Example of Usage:
  2944.               les  DI, String
  2945.               mov  DX, seg CharSet
  2946.               lea  SI, CharSet
  2947.               Strcspan          ; find first position in String with a
  2948.               mov i, CX         ;                      char in CharSet
  2949.               printf
  2950.               db  "The first char which is in CharSet "
  2951.               db  "occurs at position %d in String.\n",0
  2952.               dd  i
  2953.  
  2954.               les  DI, String
  2955.               Strcspanl         ; find first position in String which
  2956.               db   "aeiou",0    ; is a vowel.
  2957.               mov  j, CX
  2958.               printf
  2959.               db  "The first char which is a vowel occurs "
  2960.               db  "at position %d in String.\n",0
  2961.               dd  j
  2962.  
  2963.  
  2964. Description:  Strcspan(l) scans a string, counting the number of characters
  2965.           which are NOT present in a second string (which represents a
  2966.           character set).  ES:DI points at a zero-terminated string of
  2967.           characters to scan.  DX:SI (strcspan) or CS:RET (strcspanl) points
  2968.           at another zero-terminated string containing the set of characters
  2969.           to compare against.  The position of the first character in the
  2970.           string pointed to by ES:DI which is in the character set is
  2971.           returned.  If all the characters in the string are not in the
  2972.           character set, the position of the zero-terminating byte will be
  2973.           returned.
  2974.  
  2975.           Although strcspan and strcspanl are very compact and convenient to
  2976.           use, they are not particularly efficient.  The character set
  2977.           routines provide a much faster alternative at the expense of a
  2978.           little more space.
  2979.  
  2980. Include:              stdlib.a
  2981.  
  2982.  
  2983. Routine:  StrIns (m,l,ml)
  2984. -------------------------
  2985.  
  2986. Category:             String Handling Routine
  2987.  
  2988. Registers on Entry:   ES:DI - Pointer to destination string (to insert into)
  2989.               DX:SI - Pointer to string to insert
  2990.                       (StrIns and StrInsm only)
  2991.               CX    - Insertion point in destination string
  2992.  
  2993. Registers on Return:  ES:DI - Pointer to new string (StrInsm and StrInsml only)
  2994.  
  2995. Flags Affected:       Carry = 0 if no error
  2996.               Carry = 1 if insufficient memory
  2997.                    (StrInsm and StrInsml only)
  2998.  
  2999.  
  3000. Example of Usage:
  3001.               les  DI, DestStr
  3002.               mov  DX, word ptr SrcStr+2
  3003.               mov  SI, word ptr SrcStr
  3004.               mov  CX, 5
  3005.               StrIns     ; Insert SrcStr before the 6th char of DestStr
  3006.  
  3007.               les  DI, DestStr
  3008.               mov  CX, 2
  3009.               StrInsl    ; Insert "Hello" before the 3rd char of DestStr
  3010.               db  "Hello",0
  3011.  
  3012.               les  DI, DestStr
  3013.               mov  DX, word ptr SrcStr+2
  3014.               mov  SI, word ptr SrcStr
  3015.               mov  CX, 11
  3016.               StrInsm      ; Create a new string by inserting SrcStr
  3017.                    ;         before the 12th char of DestStr
  3018.               puts
  3019.               putcr
  3020.               free
  3021.  
  3022.  
  3023. Description:  These routines insert one string into another string.  ES:DI
  3024.           points at the string into which you want to insert another.  CX
  3025.           contains the position (or index) where you want the string
  3026.           inserted.  This index is zero-based, so if CX contains zero, the
  3027.           source string will be inserted before the first character in the
  3028.           destination string.  If CX contains a value larger than the size
  3029.           of the destination string, the source string will be appended to
  3030.           the destination string.
  3031.  
  3032.           StrIns inserts the string pointed at by DX:SI into the string
  3033.           pointed at by ES:DI at position CX.  The buffer pointed at by
  3034.           ES:DI must be large enough to hold the resulting string.  StrIns
  3035.           does NOT perform bounds checking on the data.
  3036.  
  3037.      ( continued on next page )
  3038.  
  3039.  
  3040. Routine:  StrIns (m,l,ml)   ( continued )
  3041. -----------------------------------------
  3042.  
  3043.           StrInsm does not modify the source or destination strings, but
  3044.           instead attempts to allocate a new buffer on the heap to hold the
  3045.           resulting string.  If it is not successful, StrInsm returns with
  3046.           the Carry flag set, otherwise the resulting string is created and
  3047.           its address is returned in the ES:DI registers.
  3048.  
  3049.           StrInsl and StrInsml work just like StrIns and StrInsm except you
  3050.           supply the second string as a literal constant immediately AFTER
  3051.           the call rather than pointing DX:SI at it (see examples above).
  3052.  
  3053.  
  3054.  
  3055. Routine:  StrDel, StrDelm
  3056. -------------------------
  3057.  
  3058. Category:              String Handling Routine
  3059.  
  3060. Registers on Entry:    ES:DI -  pointer to string
  3061.                CX - deletion point in  string
  3062.                AX - number of characters to delete
  3063.  
  3064. Registers on return:   ES:DI - pointer to new string (StrDelm only)
  3065.  
  3066. Flags  affected:       Carry = 1 if memory allocation error,  0 if okay
  3067.                (StrDelm only).
  3068.  
  3069. Example of Usage:
  3070.                les     di,  Str2Del
  3071.                mov     cx,  3          ; Delete starting at 4th char
  3072.                mov     ax,  5          ; Delete five characters
  3073.                StrDel                  ; Delete in place
  3074.  
  3075.                les     di,  Str2Del2
  3076.                mov     cx,  5
  3077.                mov     ax,  12
  3078.                StrDelm
  3079.                puts
  3080.                free
  3081.  
  3082.  
  3083. Description:  StrDel deletes characters from a string.  It works by computing
  3084.           the beginning and end of the deletion point.  Then it copies all
  3085.           the characters from the end of the deletion point to the end of
  3086.           the string (including the zero byte) to the beginning of the
  3087.           deletion point.  This covers up (thereby effectively deleting)
  3088.           the undesired characters in the string.
  3089.  
  3090.           Here are two degenerate cases to worry about -- 1) when you
  3091.           specify a deletion point which is beyond the end of the string;
  3092.           and 2) when the deletion point is within the string but the
  3093.           length of the deletion takes you beyond the end of the string.
  3094.           In the first case StrDel simply ignores the deletion request.  It
  3095.           does not modify the original string.  In the second case,
  3096.           StrDel simply deletes everything from the deletion point to the
  3097.           end of the string.
  3098.  
  3099.           StrDelm works just like StrDel except it does not delete the
  3100.           characters in place.  Instead, it creates a new string on the
  3101.           heap consisting of the characters up to the deletion point and
  3102.           those following the characters to delete.  It returns a pointer
  3103.           to the new string on the heap in ES:DI, assuming that it
  3104.           properly allocated the storage on the heap.
  3105.  
  3106. Include:               stdlib.a
  3107.  
  3108.  
  3109. Routine:  StrRev, StrRevm
  3110. -------------------------
  3111.  
  3112. Author:               Michael Blaszczak (.B  ekiM)
  3113.  
  3114. Category:             String Handling Routine
  3115.  
  3116. Registers on Entry:   ES:DI - pointer to string
  3117.  
  3118. Registers on return:  ES:DI - pointer to new string (StrRevm only).
  3119.  
  3120. Flags affected:       Carry  = 1 if memory allocation error, 0 if okay
  3121.               (StrRevm only).
  3122.  
  3123. Example of Usage:
  3124.  
  3125. Description:  StrRev reverses the characters in a string.  StrRev reverses,
  3126.           in place, the characters in the string that ES:SI points at.
  3127.           StrRevm creates a new string on the heap (which contains the
  3128.           characters in the string ES:DI points at, only reversed) and
  3129.           returns a pointer to the new string in ES:DI.  If StrRevm
  3130.           cannot allocate sufficient memory for the string, it returns
  3131.           with the carry flag set.
  3132.  
  3133.  
  3134. Include:              stdlib.a
  3135.  
  3136.  
  3137. Memory Management Routines
  3138. --------------------------
  3139.  
  3140. The stdlib memory management routines let you dynamically allocate storage on
  3141. the heap.  These routines are somewhat similar to those provided by the "C"
  3142. programming language.  However, these routines do not perform garbage
  3143. collection, as this would introduce too many restrictions and have a very
  3144. adverse effect on speed.
  3145.  
  3146. The following paragraph gives a description of how the memory management
  3147. routines work.  These routines may be updated in future revisions, however,
  3148. so you should never make assumptions about the structure of the memory
  3149. management record (described below) or else your code may not work on the
  3150. next revision.
  3151.  
  3152. The allocation/deallocation routines should be fairly fast.  Malloc and free
  3153. use a modified first/next fit algorithm which lets the system quickly find a
  3154. memory block of the desired size without undue fragmentation problems (average
  3155. case).  The memory manager data structure has an overhead of eight bytes
  3156. (meaning each malloc operation requires at least eight more bytes than you ask
  3157. for) and a granularity of 16 bytes.  The overhead (eight bytes) per allocated
  3158. block may seem rather high, but that is part of the price to pay for faster
  3159. malloc and free routines.  All pointers are far pointers and each new item is
  3160. allocated on a paragraph boundary.  The current memory manager routines always
  3161. allocate (n+8) bytes, rounding up to the next multiple of 16 if the result is
  3162. not evenly divisible by sixteen.  The first eight bytes of the structure are
  3163. used by the memory management routines, the remaining bytes are available for
  3164. use by the caller (malloc, et. al., return a pointer to the first byte beyond
  3165. the memory management overhead structure).
  3166.  
  3167.  
  3168.  
  3169.  
  3170. Routine:  MemInit
  3171. -----------------
  3172.  
  3173. Category:               Memory Management Routine
  3174.  
  3175. Registers on Entry:     DX - number of paragraphs to reserve
  3176.  
  3177. Globals Affected:       zzzzzzseg - segment name of the last segment in your
  3178.                     program
  3179.             PSP - public word variable which holds the PSP value
  3180.                   for your program
  3181.  
  3182. Registers on return:    CX - number of paragraphs actually reserved by MemInit
  3183.  
  3184. Flags affected:         Carry = 0 if no error.
  3185.             Carry = 1 if error; AX contains DOS error code.
  3186.  
  3187.  
  3188. Example of Usage:
  3189.                         ; Don't forget to set up PSP
  3190.                         ; and zzzzzzseg before calling
  3191.                         ; MemInit
  3192.             mov     dx, dx          ; Allocate all available RAM
  3193.             MemInit
  3194.             jc      MemoryError     ; CX contains the number of
  3195.                         ; paragraphs actually
  3196.                         ; allocated
  3197.  
  3198.  
  3199. Description:  This routine initializes the memory manager system.  You must
  3200.           call it before using any routines which call any of the memory
  3201.           manager procedures (since a good number of the stdlib routines
  3202.           call the memory manager, you should get in the habit of always
  3203.           calling this routine.)  The system will "die a horrible death"
  3204.           if you call a memory manager routine (like malloc) without first
  3205.           calling MemInit.
  3206.  
  3207.           This routine expects you to define (and set up) two global
  3208.           names: zzzzzzseg and PSP.  "zzzzzzseg" is a dummy segment which
  3209.           must be the name of the very last segment defined in your
  3210.           program.  MemInit uses the name of this segment to determine the
  3211.           address of the last byte in your program.  If you do not
  3212.           declare this segment last, the memory manager will overwrite
  3213.           anything which follows zzzzzzseg.  The "shell.asm" file
  3214.           provides you with a template for your programs which properly
  3215.           defines this segment.
  3216.  
  3217.           PSP should be a word variable which contains the program segment
  3218.           prefix value for your  program.  MS-DOS passes the PSP value to
  3219.           your program in the DS and ES registers.  You should save this
  3220.           value in the PSP variable.  Don't forget to make PSP a public
  3221.           symbol in your main program's source file.  The "shell.asm" file
  3222.           demonstrates how to properly set up this value.
  3223.  
  3224.           The DX register contnains the number of 16-byte paragraphs you
  3225.           want to reserve for the heap.  If DX contains zero, MemInit will
  3226.           allocate all of the available memory to the heap.  If your
  3227.           program is going to allow the user to run a copy of the command
  3228.           interpreter, or if your program is going to EXEC some other
  3229.           program, you should not allocate all storage to the heap.
  3230.           Instead, you should reserve  some memory for those programs.
  3231.           By setting DX to some value other than zero, you can tell MemInit
  3232.           how much memory you want to reserve for the heap.  All left over
  3233.           memory will be available for other system (or program) use.
  3234.           If the value in DX is larger than the amount of available RAM,
  3235.           MemInit will split the available memory in half and reserve half
  3236.           for the heap leaving the other half unallocated.  If you want to
  3237.           force this situation (to leave half available memory for other
  3238.           purposes), simply load DX with 0FFFFH before calling MemInit.
  3239.           There will never be this much memory available, so this will
  3240.           force MemInit to split the available RAM between the heap and
  3241.           unallocated storage.
  3242.  
  3243.           On return from MemInit, the CX register contains the number of
  3244.           paragraphs actually allocated.  You can use this value to see if
  3245.           MemInit has actually allocated the number of paragraphs you
  3246.           requested.  You  can also use this value to determine how much
  3247.           space is available when you elect to split the free space
  3248.           between the heap and the unallocated portions.
  3249.  
  3250.           If all goes well, this routine returns the carry flag clear.
  3251.           If a DOS memory manager error occurs, this routine returns the
  3252.           carry flag set and the DOS error code in the AX register.
  3253.  
  3254.  
  3255. Include:                stdlib.a
  3256.  
  3257.  
  3258. Routine:  Malloc
  3259. ----------------
  3260.  
  3261. Category:              Memory Management Routine
  3262.  
  3263. Registers on Entry:    CX - number of bytes to reserve
  3264.  
  3265. Registers on return:   CX - number of bytes actually reserved by Malloc
  3266.                ES:DI - ptr to 1st byte of memory allocated by Malloc
  3267.  
  3268. Flags affected:        Carry=0 if no error.
  3269.                Carry=1 if insufficient memory.
  3270.  
  3271. Example of Usage:
  3272.                mov     cx, 256
  3273.                Malloc
  3274.                jnc     GoodMalloc
  3275.                print   db    "Insufficient memory to continue.",cr,lf,0
  3276.                jmp   Quit
  3277.       GoodMalloc:  mov   es:[di], 0          ;Init string to NULL
  3278.  
  3279.  
  3280. Description:  Malloc is the workhorse routine you use to allocate a block of
  3281.           memory.  You give it the number of bytes you need and if it
  3282.           finds a block large enough, it will  allocate the requested
  3283.           amount and return a pointer to that block.
  3284.  
  3285.           Most memory managers require  a small amount of overhead for each
  3286.           block they allocate.  Stdlib's (current) memory manager requires
  3287.           an overhead of eight bytes.  Furthermore, the grainularity is 16
  3288.           bytes.  This means that Malloc always allocates blocks of memory
  3289.           in paragraph multiples.  Therefore, Malloc may actually reserve
  3290.           more storage than you specify. Therefore, the value returned in
  3291.           CX may be somewhat greater than the requested value.  By setting
  3292.           the minimum allocation size to a paragraph, however, the
  3293.           overhead is reduced and the speed of Malloc is improved by a
  3294.           considerable amount.
  3295.  
  3296.           Stdlib's memory management does not do any garbage collection.
  3297.           Doing so would place too many demands on Malloc's users.
  3298.           Therefore, it is quite possible for you to fragment memory with
  3299.           multiple calls to maloc, realloc, and free.  You could wind up in
  3300.           a situation where there is enough free memory to satisfy your
  3301.           request, but there isn't a single contiguous block large enough
  3302.           for the request.  Malloc treats this as an insufficient memory
  3303.           error and returns with the carry flag set.
  3304.  
  3305.           If Malloc cannot allocate a block of the requested size, it
  3306.           returns with the carry flag set.  In this situation, the contents
  3307.           of ES:DI is undefined.  Attempting to dereference this pointer
  3308.           will produce erratic and, perhaps, disasterous results.
  3309.  
  3310. Include:              stdlib.a
  3311.  
  3312.  
  3313. Routine:  Realloc
  3314. -----------------
  3315.  
  3316. Category:  Memory Management Routine
  3317.  
  3318. Registers on Entry:   CX - number of bytes to reserve
  3319.               ES:DI - pointer to block to  reallocate.
  3320.  
  3321. Registers on return:  CX - number of bytes actually reserved by Realloc.
  3322.               ES:DI - pointer to first byte of memory allocated by
  3323.                   Realloc.
  3324.  
  3325. Flags affected:       Carry = 0 if no error.
  3326.               Carry = 1 if insufficient memory.
  3327.  
  3328. Example of Usage:
  3329.             mov    cx, 1024    ;Change block size to 1K
  3330.             les    di, CurPtr    ;Get address of block into ES:DI
  3331.             realloc
  3332.             jc    BadRealloc
  3333.             mov    word ptr CurPtr, di
  3334.             mov    word ptr CurPtr+2, es
  3335.  
  3336.  
  3337. Description:  Realloc lets you change the size of an allocated block in the
  3338.           heap.  It allows you to make the block larger or smaller.
  3339.           If you make the  block smaller, Realloc simply frees (returns
  3340.           to the heap) any leftover bytes at the end of the block.  If
  3341.           you make the block larger, Realloc goes out and allocates a
  3342.           block of the requested size, copies the bytes form the old
  3343.           block to the beginning of the new block (leaving the bytes at
  3344.           the end of the new block uninitialized)), and then frees the
  3345.           old block.
  3346.  
  3347.  
  3348. Include:               stdlib.a
  3349.  
  3350.  
  3351. Routine:  Free
  3352. --------------
  3353.  
  3354. Category:               Memory Management Routine
  3355.  
  3356. Registers on Entry:     ES:DI - pointer to block to deallocate
  3357.  
  3358. Registers on return:    None
  3359.  
  3360. Flags affected:         Carry = 0 if no error.
  3361.             Carry = 1 if ES:DI doesn't point at a Free block.
  3362.  
  3363. Example of Usage:
  3364.             les     di, HeapPtr
  3365.             Free
  3366.  
  3367. Description:  Free (possibly) deallocates storage allocated on the heap by
  3368.           malloc or Realloc.  Free returns this storage to heap so other
  3369.           code can reuse it later.  Note, however, that Free doesn't
  3370.           always return storage to the heap.  The memory manager data
  3371.           structure keeps track of the number of pointers currently
  3372.           pointing at a block on the heap (see DupPtr, below).  If you've
  3373.           set up several pointers such that they point at the same block,
  3374.           Free will not deallocate the storage until you've freed all of
  3375.           the pointers which point at the block.
  3376.  
  3377.           Free usually returns an error code (carry flag = 1) if you
  3378.           attempt to Free a block which is not currently allocated or if
  3379.           you pass it a memory address which was not returned by malloc
  3380.           (or Realloc).  By no means is this routine totally robust.
  3381.           If you start calling free with arbitrary pointers in es:di
  3382.           (which happen to be pointing into the heap) it is possible,
  3383.           under certain circumstances, to confuse Free and it will attempt
  3384.           to free a block it really should not.
  3385.  
  3386.           This problem could be solved by adding a large amount of extra
  3387.           code to the free routine, but it would slow it down considerably.
  3388.           Therefore, a little safety has been sacrificed for a lot of
  3389.           speed.  Just make sure your code is correct and everything will
  3390.           be fine!
  3391.  
  3392.  
  3393. Include:               stdlib.a
  3394.  
  3395.  
  3396. Routine:  DupPtr
  3397. ----------------
  3398.  
  3399. Category:             Memory Manager Routine
  3400.  
  3401. Registers on Entry:   ES:DI - pointer to block
  3402.  
  3403. Registers on return:  None
  3404.  
  3405. Flags affected:       Carry = 0 if no error.
  3406.               Carry = 1 if es:di doesn't point at a free block.
  3407.  
  3408. Example of Usage:
  3409.               les     di,  Ptr
  3410.               DupPtr
  3411.  
  3412.  
  3413. Description:  DupPtr increments the pointer count for the block at the
  3414.           specifiied address.  Malloc sets this counter to one.  Free
  3415.           decrements it by one.  If free decrements the value and it
  3416.           becomes zero, free will release the storage to the heap for
  3417.           other use.  By using DupPtr you can tell the memory manager
  3418.           that you have several pointers pointing  at the same block
  3419.           and that it shouldn't deallocate the storage until you free
  3420.           all of those pointers.
  3421.  
  3422.  
  3423. Include:              stdlib.a
  3424.  
  3425.  
  3426. Routine:  IsInHeap
  3427. ------------------
  3428.  
  3429. Category:             Memory Management Routine
  3430.  
  3431. Registers on Entry:   ES:DI - pointer to a block
  3432.  
  3433. Registers on return:  None
  3434.  
  3435. Flags affected:       Carry = 0 if ES:DI is a valid pointer.
  3436.               Carry = 1 if not.
  3437.  
  3438. Example of Usage:
  3439.             les    di, MemPtr
  3440.             IsInHeap
  3441.             jc    NotInHeap
  3442.  
  3443. Description:  This routine lets you know if es:di contains the address of
  3444.           a byte in the heap somewhere.  It does not tell you if es:di
  3445.           contains a valid pointer returned by malloc (see IsPtr, below).
  3446.           For example, if es:di contains the address of some particular
  3447.           element of an array (not necessarily the first element)
  3448.           allocated on the heap, IsInHeap will return with the carry clear
  3449.           denoting that the es:di points somewhere in the heap.  Keep in
  3450.           mind that calling this routine does not validate the pointer;
  3451.           it could be pointing at a byte which is part of the memory
  3452.           manager data structure rather than at actual data (since the
  3453.           memory manager maintains that informatnion within the
  3454.           bounds of the heap). This routine is mainly useful for seeing
  3455.           if something is allocated on the heap as opposed to somewhere
  3456.           else (like your code, data, or stack segment).
  3457.  
  3458.  
  3459. Include:              stdlib.a
  3460.  
  3461.  
  3462. Routine:  IsPtr
  3463. ---------------
  3464.  
  3465. Category:               Memory Management Routine
  3466.  
  3467. Registers on Entry:     ES:DI - pointer to block
  3468.  
  3469. Registers on return:    None
  3470.  
  3471. Flags affected:         Carry = 0 if es:di is a valid pointer.
  3472.             Carry = 1 if not.
  3473.  
  3474. Example of Usage:
  3475.             les    di, MemPtr
  3476.             IsPtr
  3477.             jc    NotAPtr
  3478.  
  3479.  
  3480.  
  3481. Description:  IsPtr is much more specific than IsInHeap.  This routine returns
  3482.           the carry flag clear if and only if es:di contains the address
  3483.           of a properly allocated (and currently allocated) block on the
  3484.           heap.  This pointer must be a value returned by Malloc, Realloc,
  3485.           or DupPtr and that block must be currently allocated for IsPtr
  3486.           to return the carry flag clear.
  3487.  
  3488.  
  3489. Include:                stdlib.a
  3490.  
  3491.  
  3492. Character Set Routines
  3493. ----------------------
  3494.  
  3495. The character set routines let you deal with groups of characters as a set
  3496. rather than a string.  A set is an unordered collection of objects where
  3497. membership (presence or absence) is the only important quality.  The stdlib
  3498. set routines were designed to let you quickly check if an ASCII character is
  3499. in a set, to quickly add characters to a set or remove characters from a set.
  3500. These operations are the ones most commonly used on character sets.  The
  3501. other operations (like union, intersection, difference, etc.) are useful, but
  3502. are not as popular as the former routines.  Therefore, the data structure
  3503. has been optimized for sets to handle the membership and add/delete operations
  3504. at the slight expense of the others.
  3505.  
  3506. Character sets are implemented via bit vectors.  A "1" bit means that an item
  3507. is present in the set and a "0" bit means that the item is absent from the
  3508. set.  The most common implementation of a character set is to use thirty-two 
  3509. consecutive bytes, eight bytes per, giving 256 bits (one bit for each char-
  3510. acter in the character set).  While this makes certain operations (like 
  3511. assignment, union, intersection, etc.) fast and convenient, other operations
  3512. (membership, add/remove items) run much slower.  Since these are the more 
  3513. important operations, a different data structure is used to represent sets.  
  3514. A faster approach is to simply use a byte value for each item in the set.  
  3515. This offers a major advantage over the thirty-two bit scheme:  for operations 
  3516. like membership it is very fast (since all you have got to do is index into 
  3517. an array and test the resulting value).  It has two drawbacks:  first, oper-
  3518. ations like set assignment, union, difference, etc., require 256 operations 
  3519. rather than thirty-two; second, it takes eight times as much memory.
  3520.  
  3521. The first drawback, speed, is of little consequence.  You will rarely use the
  3522. the operations so affected, so the fact that they run a little slower will be
  3523. of little consequence.  Wasting 224 bytes is a problem, however.  Especially
  3524. if you have a lot of character sets.
  3525.  
  3526. The approach used here is to allocate 272 bytes.  The first eight bytes con-
  3527. tain bit masks, 1, 2, 4, 8, 16, 32, 64, 128.  These masks tell you which bit
  3528. in the following 264 bytes is associated with the set.  This facilitates 
  3529. putting eight sets into 272 bytes (34 bytes per character set).  This provides
  3530. almost the speed of the 256-byte set with only a two byte overhead.  In the
  3531. stdlib.a file there is a macro that lets you define a group of character
  3532. sets:  set.  The macro is used as follows:
  3533.  
  3534.     set set1, set2, set3, ... , set8
  3535.  
  3536. You must supply between one and eight labels in the operand field.  These are
  3537. the names of the sets you want to create.  The set macro automatically 
  3538. attaches these labels to the appropriate mask bytes in the set.  The actual
  3539. bit patterns for the set begin eight bytes later (from each label).  There-
  3540. fore, the byte corresponding to chr(0) is staggered by one byte for each
  3541. set (which explains the other eight bytes needed above and beyond the 256 
  3542. required for the set).  When using the set manipulation routines, you should
  3543. always pass the address of the mask byte (i.e., the seg/offset of one of the 
  3544. labels above) to the particular set manipulation routine you are using. 
  3545. Passing the address of the structure created with the macro above will 
  3546. reference only the first set in the group.
  3547.  
  3548. Note that you can use the set operations for fast pattern matching appli-
  3549. cations.  The set membership operation for example, is much faster that the 
  3550. strspan routine found in the string package.  Proper use of character sets
  3551. can produce a program which runs much faster than some of the equivalent
  3552. string operations.
  3553.  
  3554.  
  3555. Routine:  Createsets
  3556. --------------------
  3557.  
  3558. Category:             Character Set Routine
  3559.  
  3560. Registers on Entry:   no parameters passed
  3561.  
  3562. Registers on return:  ES:DI - pointer to eight sets
  3563.  
  3564. Flags affected:       Carry = 0 if no error. Carry = 1 if insufficient
  3565.               memory to allocate storage for sets.
  3566.  
  3567. Example of Usage:
  3568.               Createsets
  3569.               jc      NoMemory
  3570.               mov     word ptr SetPtr,   di
  3571.               mov     word ptr SetPtr+2, es
  3572.  
  3573. Description:  Createsets allocates 272 bytes on the heap.   This is sufficient
  3574.           room for eight character sets.  It then initializes the first
  3575.           eight bytes of this storage with the proper mask values for
  3576.           each set.  Location es:0[di] gets set to 1, location es:1[di]
  3577.           gets 2, location es:2[di] gets 4, etc.  The Createsets routine
  3578.           also initializes all of the sets to the empty set by clearing
  3579.           all the bits to zero.
  3580.  
  3581. Include:              stdlib.a
  3582.  
  3583.  
  3584. Routine:  EmptySet
  3585. ------------------
  3586.  
  3587. Category:             Character Set Routine
  3588.  
  3589. Registers on Entry:   ES:DI - pointer to first byte of desired set
  3590.  
  3591. Registers on return:  None
  3592.  
  3593. Flags affected:          None
  3594.  
  3595. Example of Usage:
  3596.               les     di,  SetPtr
  3597.               add     di,  3          ; Point at 4th set in group.
  3598.               Emptyset
  3599.  
  3600.  
  3601. Description:  Emptyset clears out the bits in a character set to zero
  3602.           (thereby setting it to the empty set).  Upon entry, es:di must
  3603.           point at the first byte of the character set you want to clear.
  3604.           Note that this is not the address returned by Createsets.  The
  3605.           first eight bytes of a character set structure are the
  3606.           addresses of eight different sets.  ES:DI must point at one of
  3607.           these bytes upon entry into Emptyset.
  3608.  
  3609. Include:              stdlib.a
  3610.  
  3611.  
  3612. Routine:  Rangeset
  3613. ------------------
  3614.  
  3615. Category:             Character Set Routine
  3616.  
  3617. Registers on entry:   ES:DI (contains the address of the first byte of the set)
  3618.               AL    (contains the lower bound of the items)
  3619.               AH    (contains the upper bound of the items)
  3620.  
  3621. Registers on return:  None
  3622.  
  3623. Flags affected:       None
  3624.  
  3625. Example of Usage:
  3626.               lea di, SetPtr
  3627.               add di, 4
  3628.               mov al, 'A'
  3629.               mov ah, 'Z'
  3630.               rangeset
  3631.  
  3632.  
  3633. Description:  This routine adds a range of values to a set with ES:DI as the
  3634.           pointer to the set, AL as the lower bound of the set, and
  3635.           AH as the upper bound of the set (AH has to be greater than
  3636.           AL, otherwise, there will an error).
  3637.  
  3638. Include:              stdlib.a
  3639.  
  3640.  
  3641. Routine:  Addstr (l)
  3642. --------------------
  3643.  
  3644. Category:             Character Set Routine
  3645.  
  3646. Registers on Entry:   ES:DI- pointer to first byte of desired set
  3647.               DX:SI- pointer to string to add to set (Addstr only)
  3648.               CS:RET-pointer to string to add to set (Addstrl only)
  3649.  
  3650. Registers on Return:  None
  3651.  
  3652. Flags Affected:       None
  3653.  
  3654. Example of Usage:
  3655.               les     di, SetPtr
  3656.               add     di, 1           ;Point at 2nd set in group.
  3657.               mov     dx, seg CharStr ;Pointer to string
  3658.               lea     si, CharStr     ; chars to add to set.
  3659.               addstr                  ;Union in these characters.
  3660. ;
  3661.               les     di, SetPtr      ;Point at first set in group.
  3662.               addstrl
  3663.               db      "AaBbCcDdEeFf0123456789",0
  3664. ;
  3665.  
  3666.  
  3667. Description:  Addstr lets you add a group of characters to a set by
  3668.           specifying a string containing the characters you want in
  3669.           the set.  To Addstr you pass a pointer to a zero-terminated
  3670.           string in dx:si.  Addstr will add (union) each character
  3671.           from this string into the set.
  3672.  
  3673.           Addstrl works the same way except you pass the string as
  3674.           a literal string constant in the code stream rather than
  3675.           via ES:DI.
  3676.  
  3677. Include:              stdlib.a
  3678.  
  3679.  
  3680. Routine:  Rmvstr (l)
  3681. --------------------
  3682.  
  3683.  
  3684. Category:             Character Set Routine
  3685.  
  3686.  
  3687. Registers on entry:   ES:DI contains the address of first byte of a set
  3688.               DX:SI contains the address of string to be removed
  3689.                  from a set (Rmvstr only)
  3690.               CS:RET pointer to string to add to set (Rmvstrl only)
  3691.  
  3692.  
  3693. Registers on return:  None
  3694.  
  3695.  
  3696. Flags affected:       None
  3697.  
  3698.  
  3699. Example of Usage:
  3700.               les     di, SetPtr
  3701.               mov     dx, seg CharStr
  3702.               lea     si, CharStr
  3703.               rmvstr
  3704.  
  3705.               mov     dx, seg CharStr
  3706.               lea     si, CharStr
  3707.               rmvstrl
  3708.               db          "ABCDEFG",0
  3709.  
  3710.  
  3711. Description:  This routine is to remove a string from a set with ES:DI
  3712.           pointing to its first byte, and DX:SI pointing to the
  3713.           string to be removed from the set.
  3714.  
  3715.           For Rmvstrl, the string of characters to remove from the
  3716.           set follows the call in the code stream.
  3717.  
  3718. Include:              stdlib.a
  3719.  
  3720.  
  3721. Routine:  AddChar
  3722. -----------------
  3723.  
  3724. Category:             Character Set Routine
  3725.  
  3726. Registers on Entry:   ES:DI- pointer to first byte of desired set
  3727.               AL- character to add to the set
  3728.  
  3729. Registers on Return:  None
  3730.  
  3731. Flags affected:       None
  3732.  
  3733. Example of Usage:
  3734.               les     di, SetPtr
  3735.               add     di, 1           ;Point at 2nd set in group.
  3736.               mov     al, Ch2Add      ;Character to add to set.
  3737.               addchar
  3738.  
  3739.  
  3740. Description:  AddChar lets you add a single character (passed in AL)
  3741.           to a set.
  3742.  
  3743. Include:              stdlib.a
  3744.  
  3745.  
  3746. Routine:  Rmvchar
  3747. -----------------
  3748.  
  3749. Category:             Character Set Routine
  3750.  
  3751. Registers on entry:   ES:DI (contains the address of first byte of a set)
  3752.               AL    (contains the character to be removed)
  3753.  
  3754. Registers on return:  None
  3755.  
  3756. Flags affected:          None
  3757.  
  3758. Example of Usage:
  3759.               lea di, SetPtr
  3760.               add di, 7        ;Point at eighth set in group.
  3761.               mov al, Ch2Rmv
  3762.               Rmvchar
  3763.  
  3764. Description:  This routine removes the character in AL from a set.
  3765.           ES:SI points to the set's mask byte. The corresponding
  3766.           bit in the set is cleared to zero.
  3767.  
  3768. Include:              stdlib.a
  3769.  
  3770.  
  3771. Routine:  Member
  3772. ----------------
  3773.  
  3774. Category:             Character Set Routine
  3775.  
  3776. Registers on entry:   ES:DI (contains the address of first byte of a set)
  3777.               AL    (contains the character to be compared)
  3778.  
  3779. Registers on return:  None
  3780.  
  3781. Flags affected:       Zero flag (Zero = 1 if the character is in the set
  3782.                  Zero = 0 if the character is not in the set)
  3783.  
  3784. Example of Usage:
  3785.               les di, SetPtr
  3786.               add di, 1
  3787.               mov al, 'H'
  3788.               member
  3789.               je IsInSet
  3790.  
  3791.  
  3792. Description:  Member is used to find out if the character in AL is in a set
  3793.           with ES:DI pointing to its mask byte. If the character is in
  3794.           the set, the zero flag is set to 1. If not, the zero flag is
  3795.           set to zero.
  3796.  
  3797. Include:              stdlib.a
  3798.  
  3799.  
  3800. Routine:  CopySet
  3801. -----------------
  3802.  
  3803. Category:            Character Set Routine
  3804.  
  3805. Register on entry:   ES:DI- pointer to first byte of destination set.
  3806.              DX:SI- pointer to first byte of source set.
  3807.  
  3808. Register on Return:  None
  3809.  
  3810. Flags affected:      None
  3811.  
  3812. Example of Usage:
  3813.              les     di, SetPtr
  3814.              add     di, 7           ;Point at 8th set in group.
  3815.              mov     dx, seg SetPtr2 ;Point at first set in group.
  3816.              lea     si, SetPtr2
  3817.              copyset
  3818.  
  3819.  
  3820. Description:  CopySet copies the items from one set to another.  This is a
  3821.           straight assignment, not a union operation.  After the
  3822.           operation, the destination set is identical to the source set,
  3823.           both in terms of the element present in the set and absent
  3824.           from the set.
  3825.  
  3826.  
  3827. Include:             stdlib.a
  3828.  
  3829.  
  3830. Routine:  SetUnion
  3831. ------------------
  3832.  
  3833. Category:            Character Set Routine
  3834.  
  3835. Register on entry:   ES:DI - pointer to first byte of destination set.
  3836.              DX:SI - pointer to first byte of source set.
  3837.  
  3838. Register on return:  None
  3839.  
  3840. Flags affected:      None
  3841.  
  3842. Example of Usage:    les   di, SetPtr
  3843.              add   di, 7              ;point at 8th set in group.
  3844.              mov   dx, seg SetPtr2    ;point at 1st set in group.
  3845.              lea   si, sSetPtr2
  3846.              unionset
  3847.  
  3848.  
  3849. Description:  The SetUnion routine computes the union of two sets.
  3850.           That is, it adds all of the items present in a source set
  3851.           to a destination set.  This operation preserves items
  3852.           present in the destination set before the SetUnion
  3853.           operation.
  3854.  
  3855. Include:             stdlib.a
  3856.  
  3857.  
  3858. Routine:  SetIntersect
  3859. ----------------------
  3860.  
  3861. Category:            Character Set Routine
  3862.  
  3863. Register on entry:   ES:DI - pointer to first byte of destination set.
  3864.              DX:SI - pointer to first byte of source set.
  3865.  
  3866. Register on return:  None
  3867.  
  3868. Flags affected:      None
  3869.  
  3870. Example of Usage:
  3871.              les   di, SetPtr
  3872.              add   di, 7              ;point at 8th set in group.
  3873.              mov   dx, seg SetPtr2    ;point at 1st set in group.
  3874.              lea   si, SetPtr2
  3875.              setintersect
  3876.  
  3877. Description:  SetIntersect computes the intersection of two sets, leaving
  3878.           the result in the destination set.  The new set consists
  3879.           only of those items which previously appeared in
  3880.           both the source and destination sets.
  3881.  
  3882. Include:             stdlib.a
  3883.  
  3884.  
  3885. Routine:  SetDifference
  3886. -----------------------
  3887.  
  3888. Category:            Character Set Routine
  3889.  
  3890. Register on entry:   ES:DI - pointer to the first byte of destination set.
  3891.              DX:SI - pointer to the first byte of the source set.
  3892.  
  3893. Register on return:  None
  3894.  
  3895. Flags affected:      None
  3896.  
  3897. Example of Usage:
  3898.              les   di, SetPtr
  3899.              add   di, 7               ;point at 8th set in group.
  3900.              mov   dx, seg SetPtr2     ;point at 1st set in group.
  3901.              lea   si, SetPtr2
  3902.              setdifference
  3903.  
  3904.  
  3905. Description:  SetDifference computes the result of (ES:DI) := (ES:DI) -
  3906.           (DX:SI).  The destination set is left with its original
  3907.           items minus those items which are also in the source set.
  3908.  
  3909. Include:             stdlib.a
  3910.  
  3911.  
  3912. Routine:  Nextitem
  3913. ------------------
  3914.  
  3915. Category:             Character Set Routine
  3916.  
  3917. Registers on entry:   ES:DI (contains the address of first byte of the set)
  3918.  
  3919. Registers on return:  AL (contains the first item in the set)
  3920.  
  3921. Flags affected:       None
  3922.  
  3923. Example of Usage:
  3924.               les di, SetPtr
  3925.               add di, 7        ;Point at eighth set in group.
  3926.               nextitem
  3927.  
  3928.  
  3929. Description:  Nextitem is the routine to search the first character (item)
  3930.           in the set with ES:DI pointing to its mask byte. AL will
  3931.           return the character in the set. If the set is empty, AL
  3932.           will contain zero.
  3933.  
  3934. Include:              stdlib.a
  3935.  
  3936.  
  3937. Routine:  Rmvitem
  3938. -----------------
  3939.  
  3940. Category:             Character Set Routine
  3941.  
  3942. Registers on entry:   ES:DI (contains the address fo first byte of the set)
  3943.  
  3944. Registers on return:  AL (contains the first item in the set)
  3945.  
  3946. Flags affected:       None
  3947.  
  3948. Example of Usage:
  3949.               les di, SetPtr
  3950.               add di, 7
  3951.               rmvitem
  3952.  
  3953. Description:  Rmvitem locates the first available item in the set and
  3954.           removes it with ES:DI pointing to its mask byte. AL will
  3955.           return the item removed. If the set is empty, AL will
  3956.           return zero.
  3957.  
  3958. Include:              stdlib.a
  3959.  
  3960.  
  3961.  
  3962. Floating Point Routines
  3963. -----------------------
  3964.  
  3965. The floating point routines provide a basic floating point package for
  3966. 80x86 assembly language users.  The floating point package deals with
  3967. four different floating point formats: IEEE 32-bit, 64-bit, and 80-bit
  3968. formats, and an internal 81-bit format.  The external formats mostly
  3969. support the IEEE standard except for certain esoteric values such as
  3970. denormalized numbers, NaNs, infinities, and other such cases.
  3971.  
  3972. The package provides two "pseudo-registers", a floating point accumulator
  3973. and a floating point operand.  It provides routines to load and store these
  3974. pseudo-registers from memory operands (using the various formats) and then
  3975. all other operations apply to these two operands.  All computations use the
  3976. internal 81-bit floating point format.  The package automatically converts
  3977. between the internal format and the external format when loading and storing
  3978. values.
  3979.  
  3980. Do not write code which assumes the internal format is 81 bits.  This format
  3981. will change in the near future when I get a chance to add guard bits to
  3982. all the computations.  If your code assumes 81 bits, it will break at that
  3983. point.  Besides, there is no reason your code should count on the size of
  3984. the internal operations anyway.  Stick with the IEEE formats and you'll
  3985. be much better off (since your code can be easily upgraded to deal with
  3986. numeric coprocessors).
  3987.  
  3988. WARNING: These routines have not been sufficiently tested as of 10/10/91.
  3989. Use them with care.  Report any problems with these routines to Randy Hyde
  3990. via the electronic addresses provided in this document or by sending a
  3991. written report to UC Riverside.  As I get more time, I will further test
  3992. these routines and add additional functions to the package.
  3993.  
  3994.                     *** Randy Hyde
  3995.  
  3996.  
  3997.  
  3998. Routine:  lsfpa
  3999. ---------------
  4000.  
  4001. Category:             Floating point Routine
  4002.  
  4003. Registers on entry:   ES:DI points at a single precision (32-bit) value to load
  4004.  
  4005. Registers on return:  None
  4006.  
  4007. Flags affected:       None
  4008.  
  4009. Example of Usage:
  4010.             les di, FPValue
  4011.             lsfpa
  4012.  
  4013. Description:    LSFPA loads a single precision floating point value into the
  4014.         internal floating point accumulator.  It also converts the
  4015.         32-bit format to the internal 81-bit format used by the
  4016.         floating point package.
  4017.  
  4018. Include:    stdlib.a
  4019.  
  4020. Routine:  ssfpa
  4021. ---------------
  4022.  
  4023. Category:             Floating point Routine
  4024.  
  4025. Registers on entry:   ES:DI points at a single precision (32-bit) value where
  4026.               this routine should store the floating point acc.
  4027.  
  4028. Registers on return:  None
  4029.  
  4030. Flags affected:       Carry set if conversion error.
  4031.  
  4032. Example of Usage:
  4033.             les di, FPValue
  4034.             ssfpa
  4035.  
  4036. Description:    SSFPA stores the floating point accumulator into a single
  4037.         precision variable in memory (pointed at by ES:DI).  It
  4038.         converts the value from the 81-bit format to the 32-bit
  4039.         value before storing the result.   The 64-bit mantissa used
  4040.         by the FP package is rounded to 24 bits during the store.
  4041.         The exponent could be out of range.  If this occurs, SSFPA
  4042.         returns with the carry flag set.
  4043.  
  4044. Include:    stdlib.a
  4045.  
  4046.  
  4047. Routine:  ldfpa
  4048. ---------------
  4049.  
  4050. Category:             Floating point Routine
  4051.  
  4052. Registers on entry:   ES:DI points at a double precision (64-bit) value to load
  4053.  
  4054. Registers on return:  None
  4055.  
  4056. Flags affected:       None
  4057.  
  4058. Example of Usage:
  4059.             les di, FPValue
  4060.             ldfpa
  4061.  
  4062. Description:    LDFPA loads a double precision floating point value into the
  4063.         internal floating point accumulator.  It also converts the
  4064.         64-bit format to the internal 81-bit format used by the
  4065.         floating point package.
  4066.  
  4067. Include:    stdlib.a
  4068.  
  4069. Routine:  sdfpa
  4070. ---------------
  4071.  
  4072. Category:             Floating point Routine
  4073.  
  4074. Registers on entry:   ES:DI points at a double precision (64-bit) value where
  4075.               this routine should store the floating point acc.
  4076.  
  4077. Registers on return:  None
  4078.  
  4079. Flags affected:       Carry set if conversion error.
  4080.  
  4081. Example of Usage:
  4082.             les di, FPValue
  4083.             sdfpa
  4084.  
  4085. Description:    SDFPA stores the floating point accumulator into a double
  4086.         precision variable in memory (pointed at by ES:DI).  It
  4087.         converts the value from the 81-bit format to the 64-bit
  4088.         value before storing the result.   The 64-bit mantissa used
  4089.         by the FP package is rounded to 51 bits during the store.
  4090.         The exponent could be out of range.  If this occurs, SDFPA
  4091.         returns with the carry flag set.
  4092.  
  4093. Include:    stdlib.a
  4094.  
  4095.  
  4096. Routine:  lefpa
  4097. ---------------
  4098.  
  4099. Category:             Floating point Routine
  4100.  
  4101. Registers on entry:   ES:DI points at an extended precision (80-bit) value to
  4102.               load
  4103.  
  4104. Registers on return:  None
  4105.  
  4106. Flags affected:       None
  4107.  
  4108. Example of Usage:
  4109.             les di, FPValue
  4110.             lefpa
  4111.  
  4112. Description:    LEFPA loads an extended precision floating point value into
  4113.         the internal floating point accumulator.  It also converts the
  4114.         80-bit format to the internal 81-bit format used by the
  4115.         floating point package.
  4116.  
  4117. Include:    stdlib.a
  4118.  
  4119.  
  4120. Routine:  lefpal
  4121. ----------------
  4122.  
  4123. Category:             Floating point Routine
  4124.  
  4125. Registers on entry:   CS:RET points at an extended precision (80-bit) value to
  4126.               load
  4127.  
  4128. Registers on return:  None
  4129.  
  4130. Flags affected:       None
  4131.  
  4132. Example of Usage:
  4133.             lefpal
  4134.             dt    1.345e-3
  4135.  
  4136. Description:    LEFPAL loads an extended precision floating point value into
  4137.         the internal floating point accumulator.  It also converts the
  4138.         80-bit format to the internal 81-bit format used by the
  4139.         floating point package.
  4140.  
  4141.         Unlike LEFPA, LEFPAL gets its operand directly from the code
  4142.         stream.  You must follow the call to lefpal with a ten-byte
  4143.         (80-bit) floating point constant.
  4144. Include:    stdlib.a
  4145.  
  4146. Routine:  sefpa
  4147. ---------------
  4148.  
  4149. Category:             Floating point Routine
  4150.  
  4151. Registers on entry:   ES:DI points at an extended precision (80-bit) value
  4152.               where this routine should store the floating point acc.
  4153.  
  4154. Registers on return:  None
  4155.  
  4156. Flags affected:       Carry set if conversion error.
  4157.  
  4158. Example of Usage:
  4159.             les di, FPValue
  4160.             sefpa
  4161.  
  4162. Description:    SEFPA stores the floating point accumulator into an extended
  4163.         precision variable in memory (pointed at by ES:DI).  It
  4164.         converts the value from the 81-bit format to the 80-bit
  4165.         value before storing the result.
  4166.  
  4167.         The exponent could be out of range.  If this occurs, SEFPA
  4168.         returns with the carry flag set.
  4169.  
  4170. Include:    stdlib.a
  4171.  
  4172.  
  4173. Routine:  lsfpo
  4174. ---------------
  4175.  
  4176. Category:             Floating point Routine
  4177.  
  4178. Registers on entry:   ES:DI points at a single precision (32-bit) value to load
  4179.  
  4180. Registers on return:  None
  4181.  
  4182. Flags affected:       None
  4183.  
  4184. Example of Usage:
  4185.             les di, FPValue
  4186.             lsfpo
  4187.  
  4188. Description:    LSFPA loads a single precision floating point value into the
  4189.         internal floating point operand.  It also converts the
  4190.         32-bit format to the internal 81-bit format used by the
  4191.         floating point package.
  4192.  
  4193. Include:    stdlib.a
  4194.  
  4195.  
  4196. Routine:  ldfpo
  4197. ---------------
  4198.  
  4199. Category:             Floating point Routine
  4200.  
  4201. Registers on entry:   ES:DI points at a double precision (64-bit) value to load
  4202.  
  4203. Registers on return:  None
  4204.  
  4205. Flags affected:       None
  4206.  
  4207. Example of Usage:
  4208.             les di, FPValue
  4209.             ldfpo
  4210.  
  4211. Description:    LDFPO loads a double precision floating point value into the
  4212.         internal floating point operand.  It also converts the
  4213.         64-bit format to the internal 81-bit format used by the
  4214.         floating point package.
  4215.  
  4216. Include:    stdlib.a
  4217.  
  4218.  
  4219. Routine:  lefpo
  4220. ---------------
  4221.  
  4222. Category:             Floating point Routine
  4223.  
  4224. Registers on entry:   ES:DI points at an extended precision (80-bit) value to
  4225.               load
  4226.  
  4227. Registers on return:  None
  4228.  
  4229. Flags affected:       None
  4230.  
  4231. Example of Usage:
  4232.             les di, FPValue
  4233.             lefpo
  4234.  
  4235. Description:    LEFPO loads an extended precision floating point value into
  4236.         the internal floating point operand.  It also converts the
  4237.         80-bit format to the internal 81-bit format used by the
  4238.         floating point package.
  4239.  
  4240. Include:    stdlib.a
  4241.  
  4242.  
  4243. Routine:  lefpol
  4244. ----------------
  4245.  
  4246. Category:             Floating point Routine
  4247.  
  4248. Registers on entry:   CS:RET points at an extended precision (80-bit) value to
  4249.               load
  4250.  
  4251. Registers on return:  None
  4252.  
  4253. Flags affected:       None
  4254.  
  4255. Example of Usage:
  4256.             lefpal
  4257.             dt    1.345e-3
  4258.  
  4259. Description:    LEFPOL loads an extended precision floating point value into
  4260.         the internal floating point operand.  It also converts the
  4261.         80-bit format to the internal 81-bit format used by the
  4262.         floating point package.
  4263.  
  4264.         Unlike LEFPO, LEFPOL gets its operand directly from the code
  4265.         stream.  You must follow the call to lefpal with a ten-byte
  4266.         (80-bit) floating point constant.
  4267. Include:    stdlib.a
  4268.  
  4269.  
  4270. Routine:  itof
  4271. --------------
  4272.  
  4273. Category:             Floating point Routine
  4274.  
  4275. Registers on entry:   AX contains a signed integer value
  4276.  
  4277. Registers on return:  None
  4278.  
  4279. Flags affected:       None
  4280.  
  4281. Example of Usage:
  4282.             mov    ax, -1234
  4283.             itof
  4284.  
  4285. Description:    ITOF converts the 16-bit signed integer in AX to a floating
  4286.         point value, storing the result in the floating point
  4287.         accumuator.
  4288.  
  4289. Include:    stdlib.a
  4290.  
  4291.  
  4292. Routine:  utof
  4293. --------------
  4294.  
  4295. Category:             Floating point Routine
  4296.  
  4297. Registers on entry:   AX contains an unsigned integer value
  4298.  
  4299. Registers on return:  None
  4300.  
  4301. Flags affected:       None
  4302.  
  4303. Example of Usage:
  4304.             mov    ax, -1234
  4305.             itof
  4306.  
  4307. Description:    UTOF converts the 16-bit unsigned integer in AX to a floating
  4308.         point value, storing the result in the floating point
  4309.         accumuator.
  4310.  
  4311. Include:    stdlib.a
  4312.  
  4313.  
  4314. Routine:  ultof
  4315. ---------------
  4316.  
  4317. Category:             Floating point Routine
  4318.  
  4319. Registers on entry:   DX:AX contains an unsigned 32-bit integer value
  4320.  
  4321. Registers on return:  None
  4322.  
  4323. Flags affected:       None
  4324.  
  4325. Example of Usage:
  4326.             mov    dx, word ptr val32+2
  4327.             mov    ax, word ptr val32
  4328.             ultof
  4329.  
  4330. Description:    ULTOF converts the 32-bit unsigned integer in DX:AX to a
  4331.         floating point value, storing the result in the floating
  4332.         point accumuator.
  4333.  
  4334. Include:    stdlib.a
  4335.  
  4336.  
  4337. Routine:  ltof
  4338. --------------
  4339.  
  4340. Category:             Floating point Routine
  4341.  
  4342. Registers on entry:   DX:AX contains a signed 32-bit integer value
  4343.  
  4344. Registers on return:  None
  4345.  
  4346. Flags affected:       None
  4347.  
  4348. Example of Usage:
  4349.             mov    dx, word ptr val32+2
  4350.             mov    ax, word ptr val32
  4351.             ltof
  4352.  
  4353. Description:    LTOF converts the 32-bit signed integer in DX:AX to a
  4354.         floating point value, storing the result in the floating
  4355.         point accumuator.
  4356.  
  4357. Include:    stdlib.a
  4358.  
  4359.  
  4360. Routine:  ftoi
  4361. --------------
  4362.  
  4363. Category:             Floating point Routine
  4364.  
  4365. Registers on entry:   None
  4366.  
  4367. Registers on return:  AX contains 16-bit signed integer
  4368.  
  4369. Flags affected:       Carry is set if conversion error occurs.
  4370.  
  4371. Example of Usage:
  4372.             ftoi
  4373.             puti        ;Print AX as integer value
  4374.  
  4375.  
  4376. Description:    FTOI converts the floating point accumulator value to a
  4377.         16-bit signed integer and returns the result in AX.  If
  4378.         the floating point number will not fit in AX, FTOI returns
  4379.         with the carry flag set.
  4380.  
  4381. Include:    stdlib.a
  4382.  
  4383.  
  4384. Routine:  ftou
  4385. --------------
  4386.  
  4387. Category:             Floating point Routine
  4388.  
  4389. Registers on entry:   None
  4390.  
  4391. Registers on return:  AX contains 16-bit unsigned integer
  4392.  
  4393. Flags affected:       Carry is set if conversion error occurs.
  4394.  
  4395. Example of Usage:
  4396.             ftou
  4397.             putu        ;Print AX as an unsigned value
  4398.  
  4399.  
  4400. Description:    FTOU converts the floating point accumulator value to a
  4401.         16-bit unsigned integer and returns the result in AX.  If
  4402.         the floating point number will not fit in AX, FTOU returns
  4403.         with the carry flag set.
  4404.  
  4405. Include:    stdlib.a
  4406.  
  4407.  
  4408. Routine:  ftol
  4409. --------------
  4410.  
  4411. Category:             Floating point Routine
  4412.  
  4413. Registers on entry:   None
  4414.  
  4415. Registers on return:  DX:AX contains a 32-bit signed integer
  4416.  
  4417. Flags affected:       Carry is set if conversion error occurs.
  4418.  
  4419. Example of Usage:
  4420.             ftol
  4421.             putl        ;Print DX:AX as integer value
  4422.  
  4423.  
  4424. Description:    FTOL converts the floating point accumulator value to a
  4425.         32-bit signed integer and returns the result in DX:AX.  If
  4426.         the floating point number will not fit in DX:AX, FTOL returns
  4427.         with the carry flag set.
  4428.  
  4429. Include:    stdlib.a
  4430.  
  4431.  
  4432. Routine:  ftoul
  4433. ---------------
  4434.  
  4435. Category:             Floating point Routine
  4436.  
  4437. Registers on entry:   None
  4438.  
  4439. Registers on return:  DX:AX contains a 32-bit unsigned integer
  4440.  
  4441. Flags affected:       Carry is set if conversion error occurs.
  4442.  
  4443. Example of Usage:
  4444.             ftoul
  4445.             putul        ;Print DX:AX as an integer value
  4446.  
  4447.  
  4448. Description:    FTOUL converts the floating point accumulator value to a
  4449.         32-bit unsigned integer and returns the result in DX:AX.  If
  4450.         the floating point number will not fit in DX:AX, FTOUL returns
  4451.         with the carry flag set.
  4452.  
  4453. Include:    stdlib.a
  4454.  
  4455.  
  4456. Routine:  fpadd
  4457. ---------------
  4458.  
  4459. Category:             Floating point Routine
  4460.  
  4461. Registers on entry:   None
  4462.  
  4463. Registers on return:  None
  4464.  
  4465. Flags affected:       None
  4466.  
  4467. Example of Usage:
  4468.             fpadd
  4469.  
  4470. Description:    FPADD adds the floating point operand to the floating point
  4471.         accumulator leaving the result in the floating point
  4472.         accumulator.
  4473.  
  4474. Include:    stdlib.a
  4475.  
  4476.  
  4477. Routine:  fpsub
  4478. ---------------
  4479.  
  4480. Category:             Floating point Routine
  4481.  
  4482. Registers on entry:   None
  4483.  
  4484. Registers on return:  None
  4485.  
  4486. Flags affected:       None
  4487.  
  4488. Example of Usage:
  4489.             fpsub
  4490.  
  4491. Description:    FPSUB subtracts the floating point operand from the floating
  4492.         point accumulator leaving the result in the floating point
  4493.         accumulator.
  4494.  
  4495. Include:    stdlib.a
  4496.  
  4497.  
  4498. Routine:  fpcmp
  4499. ---------------
  4500.  
  4501. Category:             Floating point Routine
  4502.  
  4503. Registers on entry:   None
  4504.  
  4505. Registers on return:  AX contains result of comparison.
  4506.  
  4507. Flags affected:       As appropriate for a comparison.  You can use the
  4508.               conditional branches to check the comparison after
  4509.               calling this routine.  Be sure to use the *signed*
  4510.               conditional jumps (e.g., JG, JGE, etc.).
  4511.  
  4512. Example of Usage:
  4513.             fpcmp
  4514.             jge    FPACCgeFPOP
  4515.  
  4516. Description:    FPCMP compares the floating point accumulator to the
  4517.         floating point operand and sets the flags according to the
  4518.         result of the comparison.  It also returns a value in AX
  4519.         as follows:
  4520.  
  4521.             AX    Result
  4522.             -1    FPACC < FPOP
  4523.              0    FPACC = FPOP
  4524.              1    FPACC > FPOP
  4525.  
  4526. Include:    stdlib.a
  4527.  
  4528.  
  4529. Routine:  fpmul
  4530. --------------
  4531.  
  4532. Category:             Floating point Routine
  4533.  
  4534. Registers on entry:   None
  4535.  
  4536. Registers on return:  None
  4537.  
  4538. Flags affected:       None
  4539.  
  4540. Example of Usage:
  4541.             fpmul
  4542.  
  4543. Description:    FPMUL multiplies the floating point accumulator by the floating
  4544.         point operand and leaves the result in the floating point
  4545.         accumulator.
  4546.  
  4547. Include:    stdlib.a
  4548.  
  4549.  
  4550. Routine:  fpdiv
  4551. ---------------
  4552.  
  4553. Category:             Floating point Routine
  4554.  
  4555. Registers on entry:   None
  4556.  
  4557. Registers on return:  None
  4558.  
  4559. Flags affected:       None
  4560.  
  4561. Example of Usage:
  4562.             fpdiv
  4563.  
  4564. Description:    FPDIV divides the floating point accumulator by the floating
  4565.         point operand and leaves the result in the floating point
  4566.         accumulator.
  4567.  
  4568. Include:    stdlib.a
  4569.  
  4570.  
  4571. Routine:  ftoa (2,m)
  4572. --------------------
  4573.  
  4574. Category:             Floating point Routine
  4575.  
  4576. Registers on entry:   ES:DI points at buffer to hold result (ftoa/ftoa2 only)
  4577.               AL- Field width for floating point value.
  4578.               AH- Number of positions to the right of the dec pt.
  4579.  
  4580. Registers on return:  ES:DI points at beginning of string (ftoa/ftoam only)
  4581.               ES:DI points at zero terminating byte (ftoa2 only)
  4582.  
  4583. Flags affected:       Carry is set if malloc error (ftoam only)
  4584.  
  4585. Example of Usage:
  4586.             mov    di, seg buffer
  4587.             mov    es, di
  4588.             lea    di, buffer
  4589.             mov    ah, 2        ;Two digits after "."
  4590.             mov    al, 10        ;Use a total of ten positions
  4591.             ftoa
  4592.  
  4593.  
  4594.  
  4595. Description:    FTOA (2,M) converts the value in the floating point accumulator
  4596.         to a string of characters which represent that value.  These
  4597.         routines use a decimal representation.  The value in AH is
  4598.         the number of digits to put after the decimal point, AL
  4599.         contains the total field width (including room for the sign
  4600.         and decimal point).  The field width specification works
  4601.         just like Pascal or FORTRAN.  If the number will not fit in
  4602.         the specified field width, FTOA outputs a bunch of "#"
  4603.         characters.
  4604.  
  4605.         FTOA stores the converted string at the address specified by
  4606.         ES:DI upon entry.  There must be at least AL+1 bytes at this
  4607.         address.  It returns with ES:DI pointing at the start of this
  4608.         buffer.
  4609.  
  4610.         FTOA2 works just like FTOA except it does not preserve DI.
  4611.         It returns with DI pointing at the zero terminating byte.
  4612.  
  4613.         FTOAM allocates storage for the string on the heap and returns
  4614.         a pointer to the converted string in ES:DI.
  4615.  
  4616.         Note: this routine preserves the value in the floating point
  4617.         accumulator but it wipes out the value in the floating point
  4618.         operand.
  4619.  
  4620. Include:    stdlib.a
  4621.  
  4622.  
  4623. Routine:  etoa (2,m)
  4624. --------------------
  4625.  
  4626. Category:             Floating point Routine
  4627.  
  4628. Registers on entry:   ES:DI points at buffer to hold result (etoa/etoa2 only)
  4629.               AL- Field width for floating point value.
  4630.  
  4631. Registers on return:  ES:DI points at beginning of string (etoa/etoam only)
  4632.               ES:DI points at zero terminating byte (etoa2 only)
  4633.  
  4634. Flags affected:       Carry is set if malloc error (etoam only)
  4635.  
  4636. Example of Usage:
  4637.             mov    al, 14        ;Use a total of 14 positions
  4638.             etoam
  4639.             puts
  4640.             putcr
  4641.             free
  4642.  
  4643.  
  4644.  
  4645. Description:    ETOA (2,M) converts the value in the floating point accumulator
  4646.         to a string of characters which represent that value.  These
  4647.         routines use an exponential (scientific notation)
  4648.         representation.  AL contains the field width.  It contains
  4649.         the number of print position to use when outputting the
  4650.         number.  The field width specification works just like Pascal
  4651.         or FORTRAN.  If the number will not fit in the specified
  4652.         field width, ETOA outputs a bunch of "#" characters.
  4653.  
  4654.         ETOA stores the converted string at the address specified by
  4655.         ES:DI upon entry.  There must be at least AL+1 bytes at this
  4656.         address.  It returns with ES:DI pointing at the start of this
  4657.         buffer.
  4658.  
  4659.         ETOA2 works just like ETOA except it does not preserve DI.
  4660.         It returns with DI pointing at the zero terminating byte.
  4661.  
  4662.         ETOAM allocates storage for the string on the heap and returns
  4663.         a pointer to the converted string in ES:DI.
  4664.  
  4665.         Note: this routine preserves the value in the floating point
  4666.         accumulator but it wipes out the value in the floating point
  4667.         operand.
  4668.  
  4669. Include:    stdlib.a
  4670.  
  4671.  
  4672. Routine:  atof
  4673. --------------
  4674.  
  4675. Category:             Floating point Routine
  4676.  
  4677. Registers on entry:   ES:DI points at a string containing the representation
  4678.               of a floating point number in ASCII form.
  4679.  
  4680. Registers on return:  None
  4681.  
  4682. Flags affected:       None
  4683.  
  4684. Example of Usage:
  4685.             les    di, FPStr
  4686.             atof
  4687.  
  4688.  
  4689. Description:    ATOF converts the string pointed at by ES:DI into a floating
  4690.         point value and leaves this value in the floating point
  4691.         accumulator.  Legal floating point values are described
  4692.         by the following regular expression:
  4693.  
  4694.  
  4695.         {" "}* {+ | -} ( ([0-9]+ {"." [0-9]*}) | ("." [0-9]+)}
  4696.                 {(e | E) {+ | -} [0-9] {[0-9]*}}
  4697.  
  4698.  "{}" denote optional items.
  4699.  "|"  denotes OR.
  4700.  "()" groups items together.
  4701.  
  4702.  
  4703.  
  4704. Include:    stdlib.a
  4705.  
  4706.  
  4707.  
  4708. ******************************************************************************
  4709.  
  4710.         File I/O Routines
  4711.  
  4712.            Featuring:
  4713.                - Opening and closing files
  4714.                - Creating new files
  4715.                - Deleting files
  4716.                - Renaming files
  4717.                - File "seeking"
  4718.                - Blocked I/O:
  4719.                    - Reading from files using getc
  4720.                    - Writing to files using putc and puts
  4721.                    - File flushing
  4722.  
  4723. ******************************************************************************
  4724.  
  4725.            Written by:
  4726.  
  4727.                Mark Radleigh
  4728.                &
  4729.  
  4730.                Brian Harvey
  4731.  
  4732. ******************************************************************************
  4733.  
  4734.  
  4735. fcreate
  4736. *    Creates a new file.
  4737. *    If a file already exists with the requested name, it will be deleted
  4738.     and a new one will take its place.
  4739. Inputs: ES:DI- Contains address of the filename for the new file
  4740. Outputs: AX- If no error occured in creating the file, it contains a
  4741.         filehandle number assigned to this file by DOS.
  4742.          If an error has occurred, it contains one of the following error
  4743.         codes:
  4744.          3 - Path not found
  4745.          4 - Too many open files
  4746.          5 - Access denied
  4747.      Carry flag- 0 if no error occured, 1 if error
  4748. Include:    Stdlib.a
  4749. Updated:    6/14/91        First public release
  4750.  
  4751. This routine creates a new file on the specified pathname. If no pathname or
  4752. device is specified, the file will be created in the current working directory.
  4753. If the file has been successfully created (No errors occured!), then this
  4754. routine returns in the ax register a number that is the DOS filehandle for
  4755. this file. Don't lose this value. You will need it when to want to close the
  4756. file (using fclose). Save the ax register in a variable after the routine call
  4757. and move the variable back into the ax register before you call the fclose
  4758. stdlib routine. See documentation for fclose for more information.
  4759.  
  4760. FILEHANDLE NOTICE: The filehandle returned in the ax register is not the true
  4761. DOS filehandle for this file. However, this filehandle is too be used when
  4762. calling the file routines in stdlib. In order to get the true filehandle for a
  4763. certain file, see the documentation for the stdlib routine, DOSHandle
  4764.  
  4765. Example:
  4766.  
  4767.         print
  4768.         db      "What do you desire to create?",0
  4769.         gets                            ;Get filename and store in es:di
  4770.         fcreate                      ;Call routine to create file
  4771.         jc      error                   ;If the carry flag is set,
  4772.                         ;an error has occured.
  4773.         mov     fileptr, ax             ;Save the filehandle stored in
  4774.                         ;the ax register for future
  4775.                         ;use
  4776.  
  4777. fopen
  4778. *    Opens a file for reading or writing.
  4779. *    File I/O depends on value in the al register.
  4780. Inputs: ES:DI- Contains address of the filename for the file to be opened
  4781.     AL- Contains 0 if the file is to be opened for reading.
  4782.         Contains 1 if the file is to be opened for writing.
  4783. Outputs: AX- If no error occured in opening the file, it contains a
  4784.         filehandle number assigned to this file by DOS.
  4785.          If an error has occured, it contains one of the following error
  4786.         codes:
  4787.          2 - File not found
  4788.          4 - Too many open files
  4789.          5 - Access denied
  4790.          12 - Invalid access
  4791.      Carry flag- 0 if no error occured, 1 if error
  4792. Include:    Stdlib.a
  4793. Updated:    6/14/91        First public release
  4794.  
  4795. This routine opens a file for reading or writing using the specified filename
  4796. and directory (any standard DOS file pathway) in ES:DI. Using the stdlib gets
  4797. routine is an excellent and advisable way (Not to mention an easy way!) of
  4798. getting the filename in ES:DI. The user must also move one of two values into
  4799. the al register before calling fopen. To open a file for reading, the al
  4800. register must contain the value 0 and to open a file for writing, the al
  4801. register must contain the value 1. If the file has been successfully opened, a
  4802. filehandle for this file assigned by DOS. Save this filehandle in some sort of
  4803. variable so you can move it back into the ax register when you call the stdlib
  4804. routine fclose to close the file. See documentation for fclose for more
  4805. information. Examine the examples below for a suggested way of saving the
  4806. filehandle (the example uses a variable called fileptr, but the name is
  4807. arbritary).
  4808.  
  4809. FILEHANDLE NOTICE: The filehandle returned in the ax register is not the true
  4810. DOS filehandle for this file. However, this filehandle is too be used when
  4811. calling the file routines in stdlib. In order to get the true filehandle for a
  4812. certain file, see the documentation for the stdlib routine, DOSHandle
  4813.  
  4814. NOTICE FOR MULTIPLE OPEN FILES: fopen, along with fcreate and fclose, allows the
  4815.                 user have up to 10 files open at the same time.
  4816.                 In order to keep track of all the filehandles of
  4817.                 these open files, it is suggested that a
  4818.                 separate variable for the filehandle of each
  4819.                 of the open files be used to keep track of the
  4820.                 handles.
  4821.  
  4822. Example for opening mulitple files (same theory applies with fcreate):
  4823.         print
  4824.         db      "What do you desire to open?",0
  4825.         gets                            ;Get filename and store in es:di
  4826.         mov     al, 1                   ;1 so the file will be opened
  4827.                         ;for writing
  4828.         fopen                        ;Call routine to open file
  4829.         jc      error                   ;If the carry flag is set,
  4830.                         ;an error has occured, so quit!
  4831.         mov     fileptr, ax             ;Save the filehandle stored in
  4832.                         ;the ax register for future
  4833.                         ;use
  4834.         print
  4835.         db    "What is the 2nd file you wish to open?",0
  4836.         gets
  4837.         mov    al, 1
  4838.         fopen                ;Open 2nd file for writing
  4839.         jc    error            ;Error??
  4840.         mov    fileptr2,ax        ;Save the filehandle for the 2nd
  4841.                         ;open file in a separate
  4842.                         ;variable
  4843.  
  4844.  
  4845. Warning:  If the file the user wishes to open already exists and the user wants
  4846.       to open it for writing, then the data written to the file will
  4847.       overwrite the pre-exeisting data. See docs for fseek to overcome
  4848.       this problem.
  4849.  
  4850. Example:
  4851.  
  4852. ;Open a file for writing
  4853.         print
  4854.         db      "What do you desire to open?",0
  4855.         gets                            ;Get filename and store in es:di
  4856.         mov    al, 1            ;1 so the file will be opened
  4857.                         ;for writing
  4858.  
  4859.  
  4860.         fopen                        ;Call routine to open file
  4861.         jc      error                   ;If the carry flag is set,
  4862.                         ;an error has occured, so quit!
  4863.         mov     fileptr, ax             ;Save the filehandle stored in
  4864.                         ;the ax register for future
  4865.                         ;use
  4866.  
  4867. ;Open a file for reading
  4868.         print
  4869.         db      "What do you desire to open?",0
  4870.         gets                            ;Get filename and store in es:di
  4871.         mov     al, 0                   ;0 so the file will be opened
  4872.                         ;for reading
  4873.                 fopen                        ;Call routine to open file
  4874.                 jc      error                   ;If the carry flag is set,
  4875.                                                 ;an error has occured, so quit!
  4876.         mov     fileptr, ax             ;Save the filehandle stored in
  4877.                                                 ;the ax register for future
  4878.                                                 ;use
  4879.  
  4880. fclose
  4881. *    Closes an open file
  4882. *    Filehandle for file to be closed needs to be in the ax register
  4883. Input: AX- Contains the filehandle variable of the file to close.
  4884. Outputs: AX- If carry flag is set (error occured), then ax contains an error
  4885.         code.
  4886.          If an error has occured, it contains the following error code:
  4887.         6 - Invalid file handle
  4888.         10 - Trouble with FREE (memory freeing routine)
  4889.      Carry flag- 0 if no error occured, 1 if error.
  4890. Include:    Stdlib.a
  4891. Updated:    6/14/91        First public release
  4892.  
  4893. This routine closes an open file. Once the file is closed no I/O processes
  4894. can be made on the file. Before calling the routine, fclose, the user must
  4895. move into the ax register the filehandle assigned to this file when the file
  4896. was opened or created. The only error that can occur is if the user moved into
  4897. the ax register a filehandle that does not belong to one of the opened files.
  4898. The following example demonstrates how to close a file that was opened in one of
  4899. the fopen examples or the file that was created in the fcreate example, whose
  4900. filehandle was saved in variable called fileptr.
  4901. Example:
  4902.                 mov     ax, fileptr        ;Move the DOS filehandle into
  4903.                         ;the ax register before
  4904.                         ;calling routine
  4905.                 fclose                ;Close the file
  4906.                 cmp     ax, 6            ;If the filehandle was an
  4907.                         ;invalid filehandle jump to
  4908.                         ;user's code for error's
  4909.                 je      error
  4910. ;The following code is a continuation in the case that multiple files are
  4911. ;open. The code close the second open file.
  4912.         mov    ax, fileptr2
  4913.         fclose
  4914.         cmp    ax, 6
  4915.         je    error
  4916.  
  4917. fwriteon
  4918. *    Turns on the write to file mode.
  4919. *    Redirects the ouput of stdlib routines putc and puts to a open file
  4920. Input: AX- Contains the filehandle of which open file to write data to.
  4921. Outputs: AX- If an error occurs in attempting to write to a file, ax will
  4922.         contain one of the following error codes:
  4923.           5 - Accessed denied
  4924.           6 - Invalid handle
  4925.      Carry flag- 0 if no error occured, 1 if error.
  4926. Include:    Stdlib.a
  4927. Updated:    6/14/91        First public release
  4928.  
  4929. This routine turns the write to disk mode on. In other words, it redirects the
  4930. output of the stdlib putc routine so that instead of writing data to the screen,
  4931. the data is written to the file whose filehandle is in the ax register when
  4932. fwriteon is called. The routine that replaces the output device of putc's ouput
  4933. actually uses what is known as Blocked I/O. Instead of writing one character
  4934. to the file each time the user calls getc, each character is stored in a buffer
  4935. in memory. When the buffer contains 256 characters, that buffer is written to
  4936. the file as a block. The buffer is then cleared and more characters can be read
  4937. with getc. Using blocked I/O is a lot faster than one character at a time. Along
  4938. with getc, the stdlib routine gets' ouput is also redirected during fwriteon
  4939. mode, since in the stdlib, gets actually just calls getc many times.
  4940.  
  4941. Example:
  4942. ;This code would appear in a program after a file has been created or opened
  4943. ;for "gets"
  4944.         mov    ax, fileptr        ;Move into ax filehandle of
  4945.                         ;file to write to
  4946.                 fwriteon                     ;Call function to redirect
  4947.                                                 ;the output of putc and puts
  4948.         puts
  4949.         fwriteoff            ;Turn off write to disk mode
  4950.         puts
  4951. ;The puts must appear after the fwriteoff command because gets automatically
  4952. ;writes whatever is in ES:DI to the screen (or in this case the file). The puts
  4953. ;appearing after the writeoff, prints whatever is at ES:DI to the screen. If
  4954. ;the puts were to appear in the writeoon mode, the string at ES:DI would be
  4955. ;written to the file twice
  4956.  
  4957. Example:
  4958. ;This code would appear in a program after a file has been created or opened
  4959. ;for "getc"
  4960.         mov    ax, fileptr        ;Move into ax filehandle of
  4961.                         ;file to write to
  4962.         fwriteon                 ;Call function to redirect
  4963.                         ;the output of putc and puts
  4964.         getc
  4965.         putc
  4966.         fwriteoff
  4967. ;Unlike in the previous example, getc and putc may both appear in the writeon
  4968. ;mode. The getc will get a character from the keyboard and store it in the al
  4969. ;register. Putc will then write whatever is in the al register to the
  4970. ;specified open file. In order for the user to see what character they typed
  4971. ;in, in the previous example, a putc should appear after the fwriteoff call.
  4972. ;Since fwriteoff redirects the putc ouput back to normal (See docs for fwriteoff
  4973. ;for more info) the character in al will be put on the screen.
  4974.  
  4975. fwriteoff
  4976. *    Turns off the write to file mode
  4977. *    Redirects the output of putc back to normal (the screen!)
  4978.         mode.
  4979. Include:    Stdlib.a
  4980. Updated:    6/14/91        First public release
  4981.  
  4982. This routines changes or redirects the ouput of stdlib's putc back to normal.
  4983. In other words, since the routine fwriteon made the ouput go to a disk file,
  4984. changing it back to normal means that after this routine is called, all putc's
  4985. used will print whatever is in the al register to the screen.
  4986.  
  4987. Example:
  4988. ;This example gets a character from the keyboard, prints to a disk file and then
  4989. ;prints to the screen the character in the al register that was entered.
  4990.         mov    ax, fileptr        ;Move into ax filehandle of
  4991.                         ;file to write to
  4992.         fwriteon                 ;Call function to redirect
  4993.                         ;the output of putc and puts
  4994.         getc                ;Get character and store in al
  4995.         putc                ;Print character in al to file
  4996.         fwriteoff            ;Change ouput of putc back to
  4997.                         ;normal
  4998.         putc                ;Prints character in al to
  4999.                         ;screen
  5000. fflush
  5001. *    Flushes the buffer in an opened write file to that file
  5002. Inputs:    AX- Contains Stdlib filehandle of file whose buffer is to be flushed
  5003. Outputs: None.
  5004. Include:    Stdlib.a
  5005. Updated:        6/14/91         First public release
  5006.  
  5007. This routine takes all data from the buffer associated with the Stdlib
  5008. filehandle passed in AX and writes it to the file. It then clears the buffer.
  5009. NOTE: This routine is automatically called on by Fclose.
  5010.  
  5011. freadon
  5012. *    Turns on the read from file mode
  5013. *    Changes the source of the input for the stdlib function getc
  5014. Input:    AX- Contains the filehandle of which open file to read data from.
  5015. Output: AL- Contains a character read from the specified file.
  5016.     AX- If an error occurs in attempting to read from a file, ax will
  5017.         contain one of the following error codes:
  5018.           5 - Access denied
  5019.           6 - Invalid handle
  5020.           8 - EOF
  5021.     Carry flag- 0 if no error occured, 1 if error.
  5022. Include:    Stdlib.a
  5023. Updated:    6/14/91        First public release
  5024.  
  5025. This routine turns the read from file mode on. It redirects the source from
  5026. which stdlib's getc routine gets its "character" from. Instead of getting the
  5027. character from the keyboard, the redirected getc reads a character from a opened
  5028. file. Actually, this routine uses the blocked I/O idea discussed in the writeon
  5029. documentation. This routine when called for the first time, meaning the buffer
  5030. for the current file to be read from is clear, will read it 256 characters from
  5031. (If there is that many) a file and store it in the buffer. The first character
  5032. in the buffer is then put in the al register for the user to then use for
  5033. whatever they wish. The next time the user calls getc (without calling the
  5034. freadoff rotuine yet) the next character in the buffer will be stored in the al
  5035. register. When the buffer is empty, another 256 bytes will be read into it. When
  5036. the routine freadoff is called, any getc routines called after that will get
  5037. a character from the keyboard.
  5038.  
  5039. Example:
  5040.         mov    ax, fileptr        ;Move the filehandle of the
  5041.                         ;file to read from into ax
  5042.         freadon                ;Turn on read mode!
  5043.         mov    cx, 10            ;Set up loop to read 10
  5044.                         ;characters from a file and
  5045.                         ;print them to the screen
  5046. loop1:        getc                ;Get character from buffer and
  5047.                         ;store in al
  5048.         jc    error            ;If error in reading from file
  5049.                         ;jump to user's code for
  5050.                         ;handling code
  5051.         putc                ;Print character in al to the
  5052.                         ;screen
  5053.         loop    loop1
  5054.         freadoff            ;turn read mode off from this
  5055.                         ;file
  5056.  
  5057. freadoff
  5058. *    Turns off the read from file mode
  5059. *    Redirects the source of the data for stdlib's getc routine back to
  5060.     normal
  5061.  
  5062. This routine changes the source from which stdlib's getc routine gets its
  5063. "character" from back to normal. After calling this routine, instead of reading
  5064. characters from the disk, using blocked I/O, the getc routine will get
  5065. it's "character" from the keyboard.
  5066.  
  5067. For code example of how to use freadoff, see the example of code above for
  5068. freadon.
  5069.  
  5070.  
  5071. fseek
  5072. *    Moves the file pointer of a file to anywhere in the file
  5073. Inputs:    SI- Contains the filehandle variable of the file to be used, or "seeked"
  5074.     AL- Contains the offset from where to start the file seeking.
  5075.         0 - Seek from the begining of the file.
  5076.         1 - Seek from current pointer position
  5077.         2 - Seek backwards from the end of file
  5078.     CX:DX- Distance to move in file, in bytes.
  5079. Outputs: DX:AX- Contains the new file position if no error
  5080.      AX- One of the following error codes if an error occured while
  5081.         "seeking":
  5082.           1 - Invalid function
  5083.           6 - Invalid handle
  5084.     Carry flag- 0 if no error occured, 1 if error.
  5085. Include:    Stdlib.a
  5086. Updated:    6/14/91        First public release
  5087.  
  5088. This routine allows the user the move the file pointer to any position within
  5089. a file. You can not move backwards in a file by having a negative value in
  5090. CX:DX. The value in CX:DX must be an unsigned integer. 
  5091.  
  5092. Example:
  5093.         mov    si, fileptr        ;Move the filehandle of the
  5094.                         ;file to be seeked
  5095.         mov    al, 0            ;Start moving pointer from
  5096.                         ;beginning of file
  5097.         xor    cx, cx            ;Clear the cx register
  5098.         mov    dx, 10            ;Move file pointer 10 bytes
  5099.                         ;into file
  5100.         fseek                ;Seek!!!
  5101.         jc    error            ;Jump to error code if error
  5102.  
  5103. To find out where the file pointer currently is in the file, first xor cx and 
  5104. dx registers and call fseek. It will return in DX:AX the file pointer's
  5105. position.
  5106.         mov    si, fileptr        ;Move the filehandle of the
  5107.                         ;file to be seeked
  5108.         mov    al, 1            ;Start moving pointer from
  5109.                         ;the current position
  5110.         xor    cx, cx            ;Clear the cx register
  5111.         xor    dx, dx            ;Clear the dx register
  5112.         fseek                ;Seek!!!
  5113.         jc    error            ;Jump to error code if error
  5114.                         ;else DX:AX contains the current
  5115.                         ;File pointer position.
  5116.  
  5117.  
  5118. DOSHandle
  5119. *    Returns in the ax register the true DOS filehandle for a file
  5120. Input:    AX- Contains the filehandle for the file given to the user from
  5121.         stdlib routine, fopen or fcreate
  5122. Ouputs:    AX- Contains the true filehandle given to the requested file by DOS
  5123.     AX- If an error occured, it contains the following error code:
  5124.           1 - Invalid pseudo-filehandle
  5125.     Carry flag- 0 if no error occured, 1 if error.
  5126. Include:    Stdlib.a
  5127. Updated:    6/14/91        First public release
  5128.  
  5129. This routine returns in the ax register the true filehandle variable given by
  5130. DOS for a particular file. The filehandle returned when calling the stdlib
  5131. functions, fcreate and fopen, is not the true filehandle for the file used
  5132. in those routines. The value returned is a value created by the routines, which
  5133. stores the filehandles for multiple files in a structure in memory. The value
  5134. returned from those functions is actually the index into the structure to the
  5135. real filehandle for the file. This function, DOSHandle, returns from this
  5136. structure in memory the actual filehandle for a file that has been opened. 
  5137. NOTICE: This routine is only useful to those who need to know the real
  5138. filehandle of a file that has been created or opened with fopen or fcreate. For
  5139. those who will only be using the File I/O routines provided in stdlib then
  5140. this routine will be of no importance. It is provided only for advanced assembly
  5141. language programmers who with to do other things with files and need to know
  5142. their real filehandle values.
  5143.  
  5144. Example:
  5145.         mov    ax, fileptr        ;Move into ax the filehandle
  5146.                         ;given to the user file fopen
  5147.                         ;or fcreate
  5148.         DOSHandle            ;Get the true filehandle for
  5149.                         ;a file and store it in the
  5150.                         ;ax register
  5151.         mov    truehandle, ax
  5152.  
  5153. frename
  5154. *    Renames a file
  5155. Input:    DX:SI- Contains the original pathname of the file
  5156.     ES:DI- Contains the new pathname of the file
  5157. Ouputs:    AX- Contains one of the following error codes if an error occured:
  5158.           2 - File not found
  5159.           5 - Access denied
  5160.           17 - Not the same device
  5161.     Carry flag- 0 if no error occured, 1 if error.
  5162. Include:    Stdlib.a
  5163. Updated:    6/14/91        First public release
  5164.  
  5165. This routine renames the file whose name appears in a string at DX:SI with the
  5166. name that appears at the string pointed at by ES:DI. If an error occurs, then
  5167. an appropriate error code appears in the ax register.
  5168.  
  5169. Example:
  5170.         print
  5171.         db    "Enter the source filename: ",0
  5172.         gets
  5173.         mov    dx, es
  5174.         mov    si, di
  5175.         print
  5176.         db    cr, lf, "Enter the new filename: ",0
  5177.         gets
  5178.         frename
  5179.         jc    error
  5180.  
  5181. fdel
  5182. *    Deletes a file
  5183. Input: ES:DI- Contains the address of zero terminated pathname of file
  5184. Output: AX- Contains one of the following error codes if an error occured:
  5185.           2 - File not found
  5186.           5 - Access denied
  5187.         Carry flag- 0 if no error occured, 1 if error.
  5188. Include:        Stdlib.a
  5189. Updated:        6/14/91         First public release
  5190.  
  5191. This routine deletes the filename that is in the string that ES:DI points to.
  5192.  
  5193. Example:
  5194.         print
  5195.         db    "Name of file to delete?",0
  5196.         gets
  5197.         fdel                ;Delete the file!
  5198.         jc    error            ;Jump to error code if an error
  5199.  
  5200.  
  5201.