home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asmlib / data.doc < prev    next >
Text File  |  1994-04-12  |  41KB  |  1,251 lines

  1.  
  2. *******************************  DATA  *************************************
  3.  
  4. ASMLIB data manipulation subroutines Copyright (C) 1991 - 1993 Douglas Herr
  5. all rights reserved
  6.  
  7. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  8.  
  9. CHRDEL:      deletes a character from a string
  10. CHRNDEL:     deletes a character from a string of known length
  11.              The resulting space is closed by moving the remaining
  12.              characters forward
  13. Source:      chrdel.asm (strlen.asm)
  14.  
  15. Call with:   DS:[BX] pointing to an ASCIIZ string
  16.              (chrndel only) CX = current string length
  17.              AX = offset from DS:[BX] to character to delete
  18. Returns:     CX = new string length
  19. Uses:        CX
  20. Example:     lea   bx,string          ; DS:[BX] points to string
  21.              mov   ax,3               ; delete character at DS:[BX+3]
  22.              call  chrdel             ; delete the character, shorten string
  23.  
  24.  
  25. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  26.  
  27. COLORATTR:   calculate a color attribute for ASMLIB's text-mode subroutines.
  28.              Intended for 16-color text modes.
  29. Source:      coloratt.asm
  30. Call with:   AL = foreground color (0 - 15)
  31.              AH = background color (0 - 15)
  32. Returns:     AH = color attribute
  33. Uses:        AX
  34. Example:
  35.  
  36. include      asm.inc
  37.  
  38.       mov    al,hired            ; bright red
  39.       mov    ah,blue             ; blue
  40.       call   colorattr           ; this should get their attention
  41.       mov    warning,ah          ; save the attribute
  42.  
  43. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  44.  
  45. CSET:        centers a string in a fixed field
  46. Source:      cset.asm (strlen.asm)
  47.  
  48. Call with:   ES:[DI] = address of field string
  49.              DS:[SI] = address of string to be centered in the field
  50.              Both strings must be zero-terminated (ASCIIZ).  The field
  51.              string may not contain any nul characters except for the
  52.              terminator.
  53. Returns:     CF = 0 if no error
  54.              CF = 1 if string was truncated to fit in the field
  55. Uses:        CF; all other flags and registers are saved
  56. Example:     mov   ax,@data             ; in this case, both strings
  57.              mov   ds,ax                ; are in DGROUP
  58.              mov   es,ax
  59.              assume es:@data, ds:@data
  60.              lea   di,field             ; field string
  61.              lea   si,source            ; string to be centered in field
  62.              call  cset
  63.  
  64.  
  65. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  66.  
  67. DAYNAME:     returns a pointer to an ASCII string for specified day
  68.              of the week
  69. Source:      dname.asm ($mname.asm)
  70.  
  71. Call with:   AX = day of week (1 - 7, Sunday = 1)
  72. Returns:     ES:[BX] = pointer to day name string
  73.              CX = length of new string
  74.              Note that the day name string is not zero-terminated
  75.              strndup may be used to copy the string to the near heap
  76. Uses:        ES, BX, CX
  77. Example:     mov    ax,day
  78.              call   dayname
  79.  
  80.  
  81.  
  82. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  83.  
  84. FILL4, FILL4b: fill a buffer with specified 4-byte data
  85. Source:        tiny, small & medium: fill4.asm
  86.                huge: fill4.asm (lowES2hi.asm)
  87.  
  88. Call with:   DS:[SI] pointing to 4-byte data (integer, float or other)
  89.              ES:[DI] pointing to buffer
  90.              CX = number of 4-byte data blocks to fill in buffer
  91.              Fill4b: BX = byte increment between data blocks
  92. Returns:     nothing
  93. Uses:        nothing
  94. Example:
  95.  
  96. include asm.inc
  97.  
  98. extrn   fill4:proc
  99.  
  100. .data
  101. wonowon dd 101.      ; float4 value
  102. farseg  dw ?         ; program allocates buffer, stores seg address here
  103.  
  104. .code
  105. program fragment assumes DS:@data
  106.         .
  107.         .
  108.         .
  109.         mov   es,farseg
  110.         xor   di,di      ; start at beginning of far segment
  111.         lea   si,wonowon ; fill every other 4-byte block in far segment
  112.         mov   bx,8       ; skip 4 bytes between data blocks
  113.         mov   cx,25      ; do it 25 times
  114.         cal   fill4
  115.  
  116.  
  117.  
  118. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  119.  
  120. FILL8, FILL8b: fill a buffer with specified 8-byte data
  121. Source:        tiny, small & medium: fill8.asm
  122.                huge: fill8.asm (lowES2hi.asm)
  123.  
  124. Call with:   DS:[SI] pointing to 8-byte data (integer, float or other)
  125.              ES:[DI] pointing to buffer
  126.              CX = number of 8-byte data blocks to fill in buffer
  127.              Fill8b: BX = byte increment between data blocks
  128. Returns:     nothing
  129. Uses:        nothing
  130. Example:     see Fill4
  131.  
  132.  
  133.  
  134.  
  135. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  136.  
  137. FSTRISTR:    search for a string in a disk file, case insensetive
  138. Source:      fstristr.asm (strlen.asm, $strstr.asm, strnupr.asm)
  139.  
  140. FSTRSTR:     search for a string in a disk file, case sensetive
  141. Source:      fstrstr.asm (strlen.asm, $strstr.asm)
  142.  
  143. Call with:   BX = file handle, DS:[SI] points to string to find
  144.              The file must have been opened with read access, and at least
  145.              64k DOS memory must be free.  See STARTUP.ASM and ENDPROG.ASM.
  146. Returns:     if CF = 0, DX:AX is the offset of the string in the file
  147.              if CF = 1: memory not available if AX = DX = 0
  148.                         string not found if AX = DX = -1
  149.                         error reading file if AX = DX = -2
  150. Uses:        AX, DX, flags
  151.  
  152. Example:
  153.  
  154. extrn   fstrstr:proc
  155.  
  156. .data
  157. string   db 'A String In The File',0
  158. filename db 'anyold.fil',0
  159.  
  160. .code
  161. yoursub proc
  162.         mov      dx,offset filename
  163.         mov      ax,3D00h          ; open the file with read access
  164.         int      21h
  165.         jc       no_good
  166.         mov      bx,ax
  167.         mov      si,offset string  ; DS:[SI] points to the string
  168.         call     fstrstr
  169.         jc       no_good           ; returns with DX = high word of
  170.                                    ; string position, AX = low word
  171.  
  172.  
  173. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  174.  
  175. GETCMD:      isolates command line parameters
  176.              GetCMD assumes that parameters are separated by
  177.              one or more spaces
  178. Source:      getcmd.asm
  179.  
  180. Call with:   ES = PSP segment (see STARTUP.ASM; not requried with TINY model)
  181.              AX = parameter number (first command line parameter = 0)
  182. Returns:     ES:[BX] pointing to command line parameter
  183.              CX = length of parameter string
  184.              CX = 0 if no command parameter(AX)
  185.              Note: the string at ES:[BX] is not zero-terminated
  186. Uses:        BX
  187. Example:
  188.  
  189. include asm.inc
  190.  
  191. extrn  getcmd:proc
  192.  
  193. .data
  194. extrn  pspseg:word        ; PSP segment saved by startup code
  195.  
  196. .code
  197.        .
  198.        .
  199.        .
  200.        mov    es,pspseg
  201.        mov    ax,0        ; get first parameter
  202.        call   getcmd      ; returns with ES:[BX] pointing to parameter
  203.                           ; and CX = length of parameter
  204.        jcxz   no_parameters
  205.        
  206.  
  207.  
  208. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  209.  
  210. I2TOSTR:     convert an integer value to an ASCIIZ string
  211. Source:      i2tostr.asm
  212.  
  213. I4TOSTR:     convert a long integer value to an ASCIIZ string
  214. Source:      i4tostr.asm
  215.  
  216.              ASMLIB's TPrint, GPrint and other 'print' subroutines require
  217.              a string argument.  Numeric data must be converted to a string
  218.              before printing.
  219.  
  220. Call with:   DS:[SI] pointing to a buffer space
  221.              (i2tostr) AX = integer value
  222.              (i4tostr) DX:AX = long integer value
  223.              i2tostr requires a 7-byte (or greater) buffer;
  224.              i4tostr requires a 12-byte (or greater) buffer
  225. Returns:     ASCIIZ string at DS:[SI]; numerals are right-justified
  226. Uses:        nothing; all registers and flags are saved
  227. Supports:    (i2tostr) signed 2-byte integers
  228.              (i4tostr) signed 4-byte integers
  229. Example:
  230.  
  231. include asm.inc
  232.  
  233. extrn  i2tostr:proc
  234.  
  235. .data
  236. nbuffer  db 7 dup(?)
  237.  
  238. .code
  239.  
  240.        .
  241.        .
  242.        .
  243.        mov   ax,@data
  244.        mov   ds,ax         ; numeric buffer is in DGROUP
  245.        assume  ds:@data
  246.        lea   si,nbuffer
  247.        mov   ax,32750      ; integer value
  248.        call  i2tostr
  249.  
  250.  
  251.  
  252. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  253.  
  254. LOWDS2HI:    converts low DS:high SI address to high DS:low SI
  255.              this is handy for data structures over 64k
  256. Source:      lowds2hi.asm
  257.  
  258. Call with:   DS:[SI] = address to convert
  259. Returns:     DS:[SI] = converted address; SI <= 15
  260. Uses:        DS, SI; all other registers and flags are saved
  261. Example:
  262.  
  263. extrn   lowDS2hi:proc
  264.  
  265. .code
  266.         .
  267.         .
  268.         .
  269.         mov   ds,hugeseg
  270.         mov   si,next_data
  271.         call  lowDS2hi       ; ready to address next (65535-15) bytes
  272.  
  273.  
  274. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  275.  
  276. LOWES2HI:    converts low ES:high DI address to high ES:low DI
  277.              this is handy for data structures over 64k
  278. Source:      lowes2hi.asm
  279.  
  280. Call with:   ES:[DI] = address to convert
  281. Returns:     ES:[DI] = converted address; DI <= 15
  282. Uses:        ES, DI; all other registers and flags are saved
  283. Example:
  284.  
  285. extrn   lowES2hi:proc
  286.  
  287. .code
  288.         .
  289.         .
  290.         .
  291.         mov   es,hugeseg
  292.         mov   di,next_data
  293.         call  lowES2hi       ; ready to address next (65535-15) bytes
  294.  
  295.  
  296.  
  297. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  298.  
  299. LSET:        left-justifies a string in a fixed field
  300. Source:      lset.asm (strlen.asm)
  301.  
  302. Call with:   ES:[DI] = address of field string
  303.              DS:[SI] = address of string to be justified in the field
  304.              Both strings must be zero-terminated (ASCIIZ).  The field
  305.              string may not contain any NUL characters except for the
  306.              terminator.
  307. Returns:     CF = 0 if no error
  308.              CF = 1 if string was truncated to fit in the field
  309. Uses:        CF
  310.              all other flags and registers saved
  311. Example:     mov   ax,@data             ; in this case, both strings
  312.              mov   ds,ax                ; are in DGROUP
  313.              mov   es,ax
  314.              assume es:@data, ds:@data
  315.              lea   di,field             ; field string
  316.              lea   si,source            ; string to be justified in field
  317.              call  lset
  318.  
  319.  
  320. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  321.  
  322. LTRIM:       remove leading blanks from an ASCIIZ string
  323. Source:      ltrim.asm (strlen.asm)
  324.  
  325. Call with:   DS:[BX] pointing to string
  326. Returns:     CX = new string length
  327. Uses:        CX
  328. Example:     lea    bx,string
  329.              call   ltrim
  330.  
  331.  
  332.  
  333.  
  334. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  335.  
  336. MAXI2, MAXI2b: find maximum value in a signed integer array
  337. Source:        tiny, small & medium models: maxi2.asm
  338.                huge model: maxi2.asm (lowDS2hi.asm)
  339.  
  340. MINI2, MINI2b: find minimum value in a signed integer array
  341. Source:        tiny, small & medium models: mini2.asm
  342.                huge model: mini2.asm (lowDS2hi.asm)
  343.  
  344. MAXU2, MINU2b: find maximum value in an unsigned integer array
  345. Source:        tiny, small & medium models: maxu2.asm
  346.                huge model: maxu2.asm (lowDS2hi.asm)
  347.  
  348. MINU2, MINU2b: find minimum value in an unsigned integer array
  349. Source:        tiny, small & medium models: minu2.asm
  350.                huge model: minu2.asm (lowDS2hi.asm)
  351.  
  352. Call with:   ES:[DI] pointing to the array
  353.              CX = number of array elements
  354.              For max/min?2b, call with BX = byte increment between
  355.              array elements.  Max/min?2 assume increment = 2.
  356. Returns:     AX = array element number with maximum value
  357.              see example to calculate address of maximum value
  358.              if subroutine was called with CX = 0, CF = 1
  359. Uses:        AX, CF
  360. Example:
  361.  
  362. include asm.inc
  363.  
  364. extrn  maxi2:proc
  365.  
  366. .data
  367.  
  368. integers     dw 140 dup(0)
  369.  
  370. .code
  371.              .     ; program establishes array values
  372.              .
  373.              .
  374.              mov    ax,@data
  375.              mov    es,ax
  376.              assume es:@data
  377.              lea    di,integers
  378.              mov    cx,140        ; search the entire array
  379.              call   maxi2
  380.              shl    ax,1          ; convert word offset to byte offsest
  381.              add    di,ax         ; ES:[DI] points to the maximum value
  382.                                   ; With max/min?2b, the offset of the
  383.                                   ; value is DI + (AX * BX).
  384.  
  385. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  386.  
  387. MAXI4, MAXI4b: find maximum value in a signed 4-byte integer array
  388. Source:        tiny, small & medium models: maxi4.asm
  389.                huge model: maxi4.asm (lowDS2hi.asm)
  390.  
  391. MINI4, MINI4b: find minimum value in a signed 4-byte integer array
  392. Source:        tiny, small & medium models: mini4.asm
  393.                huge model: mini4.asm (lowDS2hi.asm)
  394.  
  395. MAXU4, MAXU4b: find maximum value in an unsigned 4-byte integer array
  396. Source:        tiny, small & medium models: maxu4.asm
  397.                huge model: maxu4.asm (lowDS2hi.asm)
  398.  
  399. MINU4, MINU4b: find minimum value in an unsigned 4-byte integer array
  400. Source:        tiny, small & medium models: minu4.asm
  401.                huge model: minu4.asm (lowDS2hi.asm)
  402.  
  403. Call with:   ES:[DI] pointing to the array
  404.              CX = number of array elements
  405.              For max/min?4b, call with BX = byte increment between
  406.              array elements.  Max/min?4 assume increment = 4.
  407. Returns:     AX = array element number with maximum value
  408.              see example to calculate address of maximum value.
  409.              if subroutine was called with CX = 0, CF = 1
  410. Uses:        AX, CF
  411. Example:
  412.  
  413. include asm.inc
  414.  
  415. extrn  maxi4:proc
  416.  
  417. .data
  418.  
  419. int4         dd 140 dup(0)
  420.  
  421. .code
  422.              .     ; program establishes array values
  423.              .
  424.              .
  425.              mov    ax,@data
  426.              mov    es,ax
  427.              assume es:@data
  428.              lea    di,int4
  429.              mov    cx,140        ; search the entire array
  430.              call   maxi4
  431.              shl    ax,1          ; convert dword offset to word offset
  432.              shl    ax,1          ; convert word offset to byte offset
  433.              add    di,ax         ; ES:[DI] points to the maximum value
  434.                                   ; With max/min?4b, the offset of the
  435.                                   ; value is DI + (AX * BX).
  436.  
  437. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  438.  
  439. MONTHNAME:   returns a pointer to an ASCII string for specified month
  440. Source:      mname.asm ($mname.asm)
  441.  
  442. Call with:   AX = month (1 - 12, January = 1)
  443. Returns:     ES:[BX] = pointer to month name string
  444.              CX = length of month string
  445.              Note that the month name string is not zero-terminated
  446.              strndup may be used to copy the string to the near heap
  447. Uses:        ES, BX, CX
  448. Example:     mov    ax,month
  449.              call   monthname
  450.              jc     no_memory
  451.  
  452.  
  453.  
  454. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  455.  
  456. NFORMAT:     formats a numeric string
  457. Source:      nformat.asm (ltrim.asm, strspace.asm, heap.asm)
  458.  
  459. Call with:   DS:[SI] pointing to a numeric string (such as one produced
  460.              by i4tostr or i2tostr)
  461.              AL = number of decimal places in output string
  462.              BL = option code
  463.               where option 1 = negative numbers enclosed with parentheses
  464.                     option 2 = commas between thousands
  465.                     option 4 = decimals truncated (instead of rounded)
  466.              assumes DS @data
  467.              Note: you must initialize the near heap with HINIT before
  468.              using NFORMAT.  See STARTUP.ASM.
  469. Returns:     DS:[BX] pointing to formatted ASCIIZ string
  470. Uses:        BX, CF
  471.  
  472. Example:
  473.  
  474. include asm.inc
  475.  
  476. extrn  nformat:proc, i2tostr:proc
  477. extrn  hinit:proc
  478.  
  479. .data
  480.  
  481. ; reserve space for the heap
  482. heapsize equ 3000                ; should be plenty
  483. hbuffer  db heapsize  dup (0)
  484.  
  485. ; I'll use this numeric buffer
  486. nbuffer  db 12 dup(0)
  487.  
  488. .code
  489. ; program fragment assumes DS:@data
  490.          .
  491.          .
  492.          .
  493.          lea    bx,hbuffer
  494.          mov    ax,heapsize
  495.          call   hinit
  496.          mov    ax,-12345
  497.          lea    si,nbuffer
  498.          call   i2tostr
  499.          mov    al,2             ; 2 decimal places
  500.          mov    bl,1 OR 2        ; I want parentheses and commas
  501.          call   nformat          ; result returned at DS:[BX]
  502.                                  ; remember to release the formatted
  503.                                  ; string space with HFREE when you're
  504.                                  ; done with the string
  505.  
  506. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  507.  
  508. PATH:        finds paths in program enviornment
  509.              isolates each path in "PATH=" part of enviornment
  510. Source:      path.asm (strlen.asm)
  511.  
  512. Call with:   ES = PSP segment, AX = path number.  See STARTUP.ASM.
  513. Returns:     ES:[BX] -> path(AX) in enviornment block, CX = length of path
  514.              If CX = 0, path(AX) does not exist.  The first path in the
  515.              enviornment is path(0).
  516.              Note that the path string at ES:[BX] is NOT zero-terminated.
  517. Uses:        BX, CX, ES; flags and all other registers are saved
  518. Example:     
  519.  
  520. ; program startup code saves PSP segment
  521. include asm.inc
  522.  
  523. extrn   path:proc
  524.  
  525. stacksize equ 1024
  526. .stack stacksize
  527.  
  528. .data
  529. public pspseg
  530. pspseg dw ?                          ; storage for PSP segment
  531.  
  532. .code
  533. includelib asmlib
  534. start:
  535. ; start by pointing DS to DGROUP
  536.         mov     ax,@data
  537.         mov     ds,ax
  538.         assume  ds:@data
  539.  
  540. ; save PSP segment
  541.         mov     pspseg,es
  542.          .
  543.          .
  544.          .
  545. ; sometime later in the program
  546.         xor     ax,ax        ; start with the first path
  547. find_path:
  548.         mov     es,pspseg
  549.         call    path
  550.         jcxz    no_path      ; exit if no more paths, or else copy CX bytes
  551.                              ;  at ES:[BX] to some useful location (try
  552.                              ;  strndup).
  553.         inc     ax           ; look for next path
  554.         jmp     find_path
  555.  
  556. no_path:
  557.  
  558.  
  559. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  560.  
  561. QFNAME:      qualifies a filename
  562. Source:      qfname.asm
  563.  
  564. Call with:   DS:[BX] pointing to a filename; the filename may contain
  565.              drive specification and/or complete or partial path name.
  566.              Drive specification and path name not required.
  567. Returns:     DS:[SI] pointing to the full DRIVESPEC:\PATH\FILENAME
  568.              CX = length of full filename
  569.              Note that DS:[SI] points to QFName's buffer space; the next
  570.              call to QFName will return a new filename at the same address.
  571. Uses:        SI, CX, flags
  572. Example:
  573.  
  574. include asm.inc
  575.  
  576. .data
  577. docs   db '*.doc',0         ; search for .DOC files in current directory
  578.  
  579. .code
  580.        .
  581.        .
  582.        .
  583.        mov    ax,@data
  584.        mov    ds,ax
  585.        lea    bx,docs
  586.        call   qfname        ; returns 'drive:\path\*.doc'
  587.  
  588.  
  589. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  590.  
  591. RANDOM:      generates a near-random number
  592. Source:      random.asm
  593.  
  594. Call with:   no parameters
  595. Returns:     AX = near-random number between 0 and 65535
  596.              you may notice repeating patterns every few thousand calls
  597.              to Random.
  598. Uses:        AX
  599. Example:     call   random
  600.  
  601.  
  602.  
  603. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  604.  
  605. RSET:        right-justifies a string in a fixed field
  606. Source:      rset.asm (strlen.asm)
  607.  
  608. Call with:   ES:[DI] = address of field string
  609.              DS:[SI] = address of string to be justified in the field
  610.              Both strings must be zero-terminated (ASCIIZ).  The field
  611.              string may not contain any nul characters except for the
  612.              terminator.
  613. Returns:     CF = 0 if no error
  614.              CF = 1 if string was truncated to fit in the field
  615. Uses:        CF; all other flags and registers saved
  616. Example:     mov   ax,@data             ; in this case, both strings
  617.              mov   ds,ax                ; are in DGROUP
  618.              mov   es,ax
  619.              assume es:@data, ds:@data
  620.              lea   di,field             ; field string
  621.              lea   si,source            ; string to be justified in field
  622.              call  rset
  623.  
  624.  
  625. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  626.  
  627. RTRIM:       removes trailing blanks from an ASCIIZ string
  628. Source:      rtrim.asm (strlen.asm)
  629.  
  630. Call with:   DS:[BX] pointing to string
  631. Returns:     CX = new string length
  632. Uses:        CX
  633. Example:     lea    bx,string
  634.              call   rtrim
  635.  
  636.  
  637.  
  638. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  639.  
  640. SORTI2HI:    sort a signed array of 2-byte integers, highest first
  641. Source:      sorti2hi.asm
  642.  
  643. SORTI2LO:    sort a signed array of 2-byte integers, lowest first
  644. Source:      sorti2lo.asm
  645.  
  646. Call with:   ES:[DI] = address of first element of array to sort
  647.              CX = number of array elements
  648. Returns:     nothing
  649. Uses:        nothing; all registers and flags are saved
  650. Example:
  651.  
  652. include asm.inc
  653.  
  654. extrn    sorti2hi:proc
  655.  
  656. .data
  657.  
  658. i2data   dw 1500 dup(0)
  659.  
  660. .code
  661.  
  662.              .      ; program establishes data values
  663.              .
  664.              .
  665.          mov    ax,@data
  666.          mov    es,ax
  667.          assume es:@data
  668.          lea    di,i2data
  669.          mov    cx,1500
  670.          call   sorti2hi
  671.  
  672.  
  673.  
  674. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  675.  
  676. SORTI4HI:    sort a signed array of 4-byte integers, highest first
  677. Source:      tiny, small & medium: sorti4hi.asm
  678.              huge: sorti4hi.asm (lowES2hi.asm)
  679.  
  680. SORTI4LO:    sort a signed array of 4-byte integers, lowest first
  681. Source:      tiny, small & medium: sorti4lo.asm
  682.              huge: sorti4lo.asm (lowES2hi.asm)
  683.  
  684. Call with:   ES:[DI] = address of first element of array to sort
  685.              CX = number of array elements
  686. Returns:     nothing
  687. Uses:        nothing; all registers and flags are saved
  688. Example:
  689.  
  690. include asm.inc
  691.  
  692. extrn    sorti4hi:proc
  693.  
  694. .data
  695.  
  696. i4data   dd 1500 dup(0)
  697.  
  698. .code
  699.  
  700.              .      ; program establishes data values
  701.              .
  702.              .
  703.          mov    ax,@data
  704.          mov    es,ax
  705.          assume es:@data
  706.          lea    di,i4data
  707.          mov    cx,1500
  708.          call   sorti4hi
  709.  
  710.  
  711.  
  712. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  713.  
  714. STRTOI2:     converts an ASCII string to equivalent integer value
  715. STRNTOI2:    converts n bytes of an ASCII string to equivalent integer value
  716.              strtoi2 and strntoi2 ignore leading blanks and tabs, then read
  717.              the string until a non-numeric character is read.
  718.              strntoi2 reads a maximum of CX characters or until a
  719.              non-numeric character is read, whichever comes first.
  720. Source:      strtoi2.asm
  721.  
  722. STRTOI4:     converts an ASCII string to a long integer value
  723. STRNTOI4:    converts n bytes of an ASCII string to a long integer value
  724.              similar to strtoi2 and strntoi2, but returning a long integer
  725.              value in DX:AX.
  726. Source:      strtoi4.asm
  727.  
  728. Call with:   DS:[SI] = address of string
  729.              strntoi2/strntoi4 only: CX = number of bytes to read
  730. Returns:     AX = integer value, or DX:AX = long integer value
  731.              strtoix:  DS:[SI] points to character past terminating byte
  732.              strntoix: if CX = 0, DS:[SI] points to next character
  733.                      if CX <> 0, DS:[SI] points to character past
  734.                      terminating byte
  735.              BL = error code
  736.                 bit 0 if set = CR read before reading any numeric characters
  737.                 bit 1 if set = CR was the terminating character
  738.                 bit 6 if set = overflow; result in DX:AX is unusable
  739.                 bit 7 if set = result is unsigned; result is unusable if the
  740.                                value represented by the string was negative
  741. Uses:        AX, BX, CX, SI, flags
  742. Example:     lea    si,long_integer  ; near address of ASCII string
  743.              mov    cx,7             ; 7-byte field
  744.              call   strntoi2         ; return result as an integer in AX
  745.  
  746.  
  747.  
  748.  
  749. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  750.  
  751. STRCAT:      catenates (combines) two ASCIIZ strings
  752. Source:      strcat.asm (strdup.asm, strlen.asm, heap.asm)
  753.  
  754. Call with:   DS:[SI] = address of first string
  755.              DS:[BX] = address of second string
  756.              assumes DS:@data
  757. Returns:     if CF = 0, DS:[BX] = address of combined ASCIIZ string
  758.              if CF = 1, insufficient memory available in near heap
  759.              Note: you must initialize the near heap with HINIT before
  760.              using STRCAT.  See STARTUP.ASM.
  761. Uses:        BX, CX, CF
  762. Example:
  763.  
  764. include asm.inc
  765.  
  766. extrn  strcat:proc
  767.  
  768. .data
  769. string0 db 'this string goes first',0
  770. string1 db ' this one is added at the end of the first',0
  771.  
  772. .code
  773. ; program fragment assumes DS:@data
  774.        .
  775.        .
  776.        .
  777.        lea    si,string0       ; address of first string
  778.        lea    bx,string1       ; address of second string
  779.        call   strcat           ; result returned at DS:[BX]
  780.        jc     heap_is_full     ; original strings are undisturbed
  781.  
  782.  
  783.  
  784. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  785.  
  786. STRCHR:      search an ASCIIZ string for a specified character
  787. STRNCHR:     search n bytes of an ASCII string for a specified character
  788. Source:      strchr.asm (strlen.asm)
  789.  
  790. Call with:   DS:[BX] = pointer to ASCIIZ string
  791.              AL = character to find
  792.              CX = number of bytes to search (strnchr only)
  793. Returns:     CX = string length
  794.              if CF = 0, AX is the offset from DS:[BX] to matching character
  795.              in the source string
  796.              if CF = 1, no matching character found
  797. Uses:        CX, AX, CF
  798.  
  799. Example on next page
  800.  
  801. ; use STRNCHR to determine if a key pressed was a legal key
  802. include asm.inc
  803.  
  804. extrn   strnchr:proc, getkey:proc, toupper:proc
  805.  
  806. .data
  807.  
  808. valid_string db 'ABC123',27      ; keys 1,2,3,A,B,C and Esc
  809. valid_len    equ $-valid_string  ; number of valid keys
  810.  
  811. dispatch_table label word
  812.         dw akey, bkey, ckey, onekey, twokey, threekey, esckey
  813.  
  814. .code
  815. ; program fragment assumes DS:@data
  816.         .
  817.         .
  818.         .
  819. get_another:
  820.         lea   bx,valid_string ; DS:[BX] points to a string of valid keys
  821.         call  getkey          ; keycode returned in AX
  822.         shr   ah,1            ; test for extended keycode
  823.         jc    get_another     ; I'm not interested in extended keycodes today
  824.  
  825.         call  toupper         ; convert keycode to upper case
  826.         mov   cx,valid_len
  827.         call  strnchr
  828.         jc    get_another     ; CF = 1 if key pressed is not among the
  829.                               ; keys in the validation string
  830.         mov   bx,ax
  831.         shl   bx,1            ; convert byte offset to word offset
  832.         jmp   dispatch_table[bx]
  833.  
  834. akey:   .
  835.         .
  836.         .
  837.  
  838. bkey:   .
  839.         .
  840.         .
  841.  
  842. ckey:   .
  843.         .
  844.         .
  845.  
  846. ; etc
  847.  
  848.  
  849.  
  850. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  851.  
  852. STRCPY:      copy an ASCIIZ string to existing buffer
  853. Source:      strcpy.asm (strlen.asm, strncpy.asm)
  854.  
  855. Call with:   ES:[BX] pointing to ASCIIZ string
  856.              DS:[SI] pointing to destination buffer
  857.              STRCPY assumes that the buffer is long enough to hold the
  858.              entire string.  The string's terminating NUL byte is not
  859.              copied to the buffer.
  860. Returns:     CX = string length
  861. Uses:        CX
  862. Example:
  863.  
  864. include asm.inc
  865.  
  866. extrn   strcpy:proc
  867.  
  868. .fardata
  869. fstring        db 'a far string',0
  870.  
  871. .data
  872. string_buffer  db 128 dup (?)
  873.  
  874. .code
  875. ; code fragment assumes DS:@data
  876.        .
  877.        .
  878.        .
  879. ; copy far string to DGROUP for convenient manipulation
  880.        mov    ax,@fardata
  881.        mov    es,ax
  882.        assume es:@fardata
  883.        mov    bx,offset @fardata:fstring
  884.        mov    si,offset @data:string_buffer
  885.        call   strcpy
  886.  
  887.  
  888. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  889.  
  890. STRNCPY:     copy CX bytes to an existing buffer
  891. Source:      strncpy.asm
  892.  
  893. Call with:   ES:[BX] pointing to ASCII string
  894.              DS:[SI] pointing to destination buffer
  895.              CX = number of bytes to copy
  896.              STRNCPY assumes that the buffer is long enough to hold the
  897.              entire string
  898. Returns:     nothing
  899. Uses:        nothing; all registers and flags are saved
  900. Example:
  901.  
  902. ; I want to copy a command line parameter to DGROUP
  903.  
  904. include asm.inc
  905. extrn   getcmd:proc
  906. extrn   strncpy:proc
  907.  
  908. .data
  909. extrn   pspseg:word             ; PSP segment address was saved by STARTUP
  910. string_buffer   db 128 dup (?)
  911.  
  912. .code
  913. ; code fragment assumes DS:@data
  914.        .
  915.        .
  916.        .
  917.        mov      es,pspseg
  918.        xor      ax,ax           ; first command line parameter
  919.        call     getcmd          ; returns parameter at ES:[BX], length as CX
  920.        jcxz     no_parameters
  921.        lea      si,string_buffer
  922.        call     strncpy
  923.  
  924. ; make it zero-terminated
  925.        add      si,cx
  926.        mov      byte ptr [si],0
  927.  
  928.  
  929. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  930.  
  931. STRINS:      inserts string1 in string0 at specified offset.
  932.              Creates new string in near heap; first part of new string
  933.              is n bytes of string0; middle of new string is string1; end
  934.              of new string is remainder of string0.
  935. Source:      strins.asm (strlen.asm, heap.asm)
  936.  
  937. Call with:   DS:[SI] pointing to string0
  938.              DS:[BX] pointing to string1
  939.              AX = offset in string0 to insert string1 (0 >= AX >= 32767)
  940.              Assumes DS:@data
  941. Returns:     if CF = 1, insufficient memory in hear heap
  942.              if CF = 0, DS:[BX] points to new string
  943.              Note: you must initialize the near heap with HINIT before
  944.              using STRINS.  See STARTUP.ASM.
  945. Uses:        BX, CF
  946. Example:
  947.  
  948. include asm.inc
  949.  
  950. extrn  strins:proc
  951.  
  952. .data
  953. string0 db '1234567890',0
  954. string1 db 'abcdefghij',0
  955.  
  956. .code
  957.        .
  958.        .
  959.        .
  960.        mov    ax,@data
  961.        mov    ds,ax            ; dgroup
  962.        assume ds:@data         ; tell MASM about it
  963.        lea    si,string0       ; address of first string
  964.        lea    bx,string1       ; address of second string
  965.        mov    ax,3             ; string1 inserted after '123'
  966.        call   strins           ; result returned at DS:[BX]
  967.        jc     heap_is_full     ; original strings are undisturbed
  968.  
  969.  
  970.  
  971. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  972.  
  973. STRDUP:      duplicates a string at ES:[BX]
  974. Source:      strdup.asm (strlen.asm, heap.asm)
  975.  
  976. STRNDUP:     duplicates n bytes of a string at ES:[BX]
  977. Source:      strndup (strdup.asm, heap.asm)
  978.  
  979. Call with:   ES:[BX] = address of source string
  980.              assumes DS:@data
  981.              (strndup) CX = number of bytes to duplicate
  982.              String copied to near heap
  983.              Source string need not be in same segment as heap
  984.              strdup requires an ASCIIZ string; strndup duplicates CX
  985.              characters at ES:[BX] whether zero-terminated or not.  The
  986.              duplicate created by strdup or strndup will be an ASCIIZ
  987.              string.
  988.  
  989. Returns:     if CF = 0, DS:[BX] = address of string copy
  990.                         CX = string length
  991.              if CF = 1, insufficient memory in near heap
  992.              Note: you must initialize the near heap with HINIT before
  993.              using STRDUP.  See STARTUP.ASM.
  994. Uses:        BX, CX, CF; all other flags and registers are saved
  995. Example:     mov  ax,@data
  996.              mov  ds,ax
  997.              mov  es,ax              ; in this case, the source string
  998.                                      ; is in the data segment
  999.              lea  bx,source          ; ES:[BX] = source address
  1000.              call strdup
  1001.              jc   oops               ; not enough memory if CF = 1
  1002.                                      ; otherwise, DS:[BX] = address
  1003.                                      ; of string copy
  1004.  
  1005.  
  1006. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1007.              
  1008. STRIPCHR:    remove all occurances of a character from an ASCIIZ string.
  1009. Source:      stripchr.asm (strlen.asm)
  1010.  
  1011. Call with:   DS:[BX] = string address
  1012.              AL = character to remove from the string
  1013. Returns:     CX = new string length
  1014. Uses:        CX
  1015. Example:     lea    bx,string        ; DS:[BX] -> string
  1016.              mov    al,'$'           ; remove "$" character from string
  1017.              call   stripchr
  1018.  
  1019.  
  1020. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1021.  
  1022. STRLEN:      finds length of an ASCIIZ string
  1023. Source:      strlen.asm
  1024.  
  1025. Call with:   DS:[BX] = address of the string
  1026. Returns:     CX = length of string excluding the terminating NUL
  1027. Uses:        CX
  1028. Example:     lea   bx,string
  1029.              call  strlen
  1030.  
  1031.  
  1032. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1033.  
  1034. STRLWR:      changes upper-case characters in a string to lower case
  1035. Source:      strlwr.asm
  1036.  
  1037. STRNLWR:     changes n bytes of a string to lower case
  1038. Source:      strnlwr.asm
  1039.  
  1040. Call with:   DS:[BX] = address of an ASCIIZ string
  1041.              CX = number of bytes (strnlwr only)
  1042. Returns:     nothing
  1043. Uses:        nothing
  1044. Example:     lea    bx,string
  1045.              call   strlwr
  1046.  
  1047.  
  1048.  
  1049. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1050.  
  1051. STRRCHR:     find the last byte in a string matching AL
  1052. STRNRCHR:    find the last byte in n bytes matching AL
  1053. Source:      strrchr.asm (strlen.asm)
  1054.  
  1055. Call with:   DS:[BX] pointing to the first character of the string
  1056.              AL = byte to find
  1057.              (strnrchr only) CX = number of bytes to search
  1058. Returns:     if CF = 1, no match
  1059.              if CF = 0, AX = offset from DS:[BX] of the last matching byte
  1060. Uses:        AX, CF; all other flags and registers are saved
  1061. Example:
  1062.  
  1063. .data
  1064. string   db 'my old computer was a real slug',0
  1065.  
  1066. .code
  1067.         .
  1068.         .
  1069.         .
  1070.          mov   ax,@data
  1071.          mov   ds,ax
  1072.          assume  ds:@data
  1073.  
  1074.          mov   al,'w'         ; look for the lower-case "w"
  1075.          lea   bx,string
  1076.          call  strrchr
  1077.          jc    oops           ; cut outta here if not in the string
  1078.                               ; else go on
  1079.  
  1080.  
  1081.  
  1082. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1083.  
  1084. STRREV:      reverses all characters in a string
  1085. STRNREV:     reverses n characters in a string
  1086. Source:      strrev.asm (strlen.asm)
  1087.  
  1088. Call with:   DS:[BX] pointing to the first character of the string
  1089.              CX = number of bytes in string to reverse (strnrev only)
  1090. Returns:     CX = string length
  1091. Uses:        CX; all other registers and flags saved
  1092. Example:     lea   bx,string          ; DS:[BX] points to ASCIIZ string
  1093.              call  strrev             ; also returns CX = string length
  1094.  
  1095.  
  1096.  
  1097. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1098.  
  1099. STRSPACE:    creates an ASCIIZ string filled with the space character,
  1100.              terminated with NUL
  1101. Source:      strspace.asm (heap.asm)
  1102.  
  1103. Call with:   AX = string length (not including terminating NUL)
  1104.              Assumes DS:@data
  1105. Returns:     if CF = 1, insufficient memory in near heap
  1106.              if CF = 0, DS:[BX] points to the new string
  1107.                         CX = string length (should be same as AX)
  1108.              Note: you must initialize the near heap with HINIT before
  1109.              using STRSPACE.  See STARTUP.ASM.
  1110. Uses:        CX, BX, CF
  1111. Example:     mov   ax,14              ; make a new string 14 characters long
  1112.              call  strspace
  1113.              jc    oops               ; not enough memory if CF = 1
  1114.              mov   string14,bx        ; else save pointer to string
  1115.  
  1116.  
  1117. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1118.  
  1119. STRSET:      sets all bytes of an ASCIIZ string to a specified character
  1120. STRNSET:     sets n bytes of an ASCIIZ string to a specified character
  1121. Source:      strset.asm (strlen.asm)
  1122.  
  1123. Call with:   DS:[BX] pointing to a valid ASCIIZ string
  1124.              AL = character
  1125.              CX = number of bytes to set (strnset only)
  1126. Returns:     CX = string length
  1127. Uses:        CX
  1128. Example:     lea   bx,string          ; DS:[BX] points to an ASCIIZ string
  1129.              mov   al,'*'
  1130.              call  strset
  1131.  
  1132.  
  1133.  
  1134.  
  1135. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1136.  
  1137. STRSTR:      finds the first match with a target string in a source string
  1138.              case sensetive
  1139. Source:      strstr.asm ($strstr.asm, strlen.asm)
  1140.  
  1141. STRISTR:     finds the first match with a target string in a source string
  1142.              case insensetive
  1143. Source:      stristr.asm (strstr.asm, strdup.asm, strlwr.asm, heap.asm)
  1144.  
  1145. STRRSTR:     finds the last match with a target string in a source string
  1146.              case sensetive
  1147. Source:      strrstr.asm (strrev.asm, $strstr.asm)
  1148.  
  1149. Call with:   ES:[DI] pointing to source string, DS:[SI] pointing to
  1150.              target string.
  1151.              STRISTR assumes DS:@data
  1152. Returns:     if CF = 0, AX = offset of target in source string.
  1153.              if CF = 1, no match
  1154.  
  1155.              Note: you must initialize the near heap with HINIT before
  1156.              using STRISTR.  See STARTUP.ASM.
  1157. Uses:        AX, CF; all other flags and registers are saved
  1158. Example:     mov   ax,@fardata
  1159.              mov   es,ax
  1160.             assume es:@fardata     ; source string is in far data area
  1161.              mov   ax,@data
  1162.              mov   ds,ax
  1163.             assume ds:@data
  1164.              lea   di,string       ; source = 'monday',0
  1165.              lea   si,substring    ; target = 'day',0
  1166.              call  strstr          ; in this example, strstr returns ax = 3
  1167.  
  1168.  
  1169. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1170.  
  1171. STRUPR:      changes lower-case characters in an ASCIIZ string to upper case
  1172. Source:      strupr.asm
  1173.  
  1174. STRNUPR:     changes lower-case characters in an n-length string to upper case
  1175. Source:      strnupr.asm
  1176.  
  1177. Call with:   DS:[BX] pointing to string
  1178.              (strnupr only) CX = number of bytes in string
  1179. Returns:     nothing
  1180. Uses:        nothing
  1181. Example:     mov    bx,offset string
  1182.              mov    cx,bytes
  1183.              call   strnupr
  1184.  
  1185.  
  1186.  
  1187. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1188.  
  1189. SWAPB:       swaps AX bytes at DS:[SI] with the same number at ES:[DI]
  1190. Source:      swapb.asm
  1191.  
  1192. Call with:   DS:[SI] pointing to one of the data areas, ES:[DI] pointing
  1193.              to the other
  1194.              AX = number of bytes to swap
  1195. Returns:     nothing
  1196. Uses:        nothing; all registers and flags are saved
  1197. Example:
  1198.  
  1199. include  asm.inc
  1200.  
  1201. extrn    swapb:proc
  1202.  
  1203. .data
  1204.  
  1205. string1  db 'this is string 1',0
  1206. string2  db 'this is string 2',0
  1207.  
  1208. strings  dw string1, string2         ; addresses of the strings
  1209.                                      ; this example will swap
  1210.                                      ; the string pointers
  1211.  
  1212. .code
  1213. public   stringswap
  1214. stringswap   proc
  1215. ; program fragment assumes DS:@data
  1216.          .
  1217.          .
  1218.          .
  1219.          lea   si,strings
  1220.          push  ds
  1221.          pop   es                    ; ES = DS
  1222.          mov   di,si
  1223.          mov   ax,2                  ; each string pointer is 2 bytes
  1224.          add   di,ax                 ; point to 2nd pointer
  1225.          call  swapb
  1226.  
  1227. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1228.  
  1229. WORDTOHEX:   Converts word data to hex (base 16) ASCIIZ string
  1230. Source:      wtohex.asm
  1231.  
  1232. Call with:   AX = word data
  1233.              DS:[SI] pointing to string buffer
  1234.               buffer must be at least 6 bytes
  1235. Returns:     DS:[SI] points to ASCIIZ string, hex format
  1236. Uses:        nothing
  1237. Example:
  1238.  
  1239. extrn   word2hex:proc
  1240. .data
  1241.  
  1242. hexbuf  db 6 dup(?)
  1243.  
  1244. .code
  1245.         .
  1246.         .
  1247.         .
  1248.         mov     ax,hexnumber
  1249.         call    wordtohex
  1250.  
  1251.