home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 181.img / TASM-101.ZIP / ENVSTR.ASM < prev    next >
Assembly Source File  |  1988-10-31  |  4KB  |  77 lines

  1. DATA      SEGMENT PUBLIC
  2.           EXTRN prefixSeg : Word       ;gives location of PSP
  3. DATA      ENDS
  4. CODE      SEGMENT PUBLIC
  5.           ASSUME cs:CODE,ds:DATA
  6.  
  7. EnvString PROC FAR
  8.           PUBLIC  EnvString
  9.           push    bp
  10.           cld                          ;work upward
  11.           mov     es,[prefixSeg]       ;look at PSP
  12.           mov     es,es:[2Ch]          ;ES:DI points at environment
  13.           xor     di,di                ;which is paragraph-aligned
  14.           mov     bp,sp                ;find the parameter address
  15.           lds     si,ss:[bp+6]         ;which is right above the return address
  16.           ASSUME  ds:NOTHING
  17.           lodsb                        ;look at length
  18.           or      al,al                ;is it zero?
  19.           jz      RetNul               ;if so, return
  20.           mov     ah,al                ;otherwise, save in AH
  21.           mov     dx,si                ;DS:DX contains pointer to first parm char
  22.           xor     al,al                ;make a zero
  23. Compare:
  24.           mov     ch,al                ;we want ch=0 for next count, if any
  25.           mov     si,dx                ;get back pointer to string sought
  26.           mov     cl,ah                ;get length
  27.           mov     si,dx                ;get pointer to string sought
  28.           repe    cmpsb                ;compare bytes
  29.           jne     Skip                 ;if compare fails, try next string
  30.           cmp     byte ptr es:[di],'=' ;compare succeeded. Is next char '='?
  31.           jne     NoEqual              ;if not, still no match
  32. Found:
  33.           mov     ax,es                ;make DS:SI point to string we found
  34.           mov     ds,ax
  35.           mov     si,di
  36.           inc     si                   ;get past the equal (=) sign
  37.           les     bx,ss:[bp+10]        ;get address of function result
  38.           mov     di,bx                ;put it in ES:DI
  39.           inc     di                   ;get past the length byte
  40.           mov     cl,255               ;set up a maximum length
  41. CopyLoop:
  42.           lodsb                        ;get a byte
  43.           or      al,al                ;zero test
  44.           jz      Done                 ;if zero, we're done
  45.           stosb                        ;put it in the result
  46.           loop    CopyLoop             ;move up to 255 bytes
  47. Done:     not     cl                   ;we've been decrementing CL from
  48.                                        ; 255 during save
  49.           mov     es:[bx],cl           ;save the length
  50.           mov     ax,SEG DATA
  51.           mov     ds,ax                ;restore DS
  52.           ASSUME  ds:DATA
  53.           pop     bp
  54.           ret     4
  55.           ASSUME  ds:NOTHING
  56. Skip:
  57.           dec     di                   ;check for null from this char on
  58. NoEqual:
  59.           mov     cx,7FFFh             ;search a long way if necessary
  60.           sub     cx,di                ;environment never >32K
  61.           jbe     RetNul               ;if we're past end, leave
  62.           repne   scasb                ;look for the next null
  63.           jcxz    RetNul               ;exit if not found
  64.           cmp     byte ptr es:[di],al  ;second null in a row?
  65.           jne     Compare              ;if not, try again
  66. RetNul:
  67.           les     di,ss:[bp+10]        ;get address of result
  68.           stosb                        ;store a zero there
  69.           mov     ax,SEG DATA
  70.           mov     ds,ax                ;restore DS
  71.           ASSUME  ds:DATA
  72.           pop     bp
  73.           ret     4
  74. EnvString ENDP
  75. CODE      ENDS
  76.           END
  77.