home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STDLIB.DOC < prev    next >
Text File  |  1991-03-13  |  144KB  |  4,645 lines

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