home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / btree / mulkey / envexec.asm < prev    next >
Encoding:
Assembly Source File  |  1988-04-08  |  2.6 KB  |  71 lines

  1. ;  Environment variable routines assembler interface to Turbo Pascal
  2. ;  Copyright 1988 by Mark R. Boler  -  All Rights Reserved
  3.  
  4. TITLE     ENVEXEC
  5.  
  6. DATA      SEGMENT WORD PUBLIC
  7.  
  8.           ASSUME  DS:DATA
  9.  
  10.           EXTRN   PREFIXSEG: WORD
  11.  
  12. DATA      ENDS
  13.  
  14. CODE      SEGMENT BYTE PUBLIC
  15.  
  16.           ASSUME  CS:CODE
  17.  
  18.           PUBLIC  EnvExec
  19.  
  20. ; FUNCTION EnvExec: STRING; EXTERNAL;
  21.  
  22. EnvDest   EQU     DWORD PTR ss:[bx + 4]
  23.  
  24. MaxStrLen EQU     80                   ; maximum length string we will return
  25. EnvOfs    EQU     [2CH]                ; offset in PSP of environment segment
  26.  
  27. EnvExec   PROC    FAR
  28.           mov     bx, sp               ; set up stack frame in bx
  29.           push    ds                   ; save ds
  30.           mov     ds, PREFIXSEG        ; get PSP into es
  31.           mov     es, ds:EnvOfs        ; get environment segment in es
  32.           xor     cx, cx               ; zero out cx
  33.           mov     di, cx               ; es:[di] = environment
  34.           mov     dl, cl               ; zero out dl
  35.           mov     al, cl               ; zero out al - we test for nul = 0
  36.           dec     cx                   ; cx = maximum integer
  37.           cld                          ; string ops go forward
  38. Loop1:
  39.           repne   scasb                ; search for a nul
  40.           jcxz    Done                 ; no match even though 64K bytes
  41.           scasb                        ; see if next byte is a nul
  42.           jne     SHORT Loop1          ; if not double nul then loop
  43.  
  44.           mov     ax, es               ; make ds:si point to environment
  45.           mov     ds, ax
  46.           mov     si, di
  47.           add     si, 2                ; point to program path string
  48.           les     di, EnvDest          ; es:di points to length byte
  49.           inc     di                   ; es:di points to string start
  50.           mov     cx, MaxStrLen        ; set cx to longest path string
  51.           mov     dl, cl               ; set dl = same
  52.  
  53. Loop2:
  54.           lodsb                        ; get a character
  55.           or      al, al               ; see if it is a nul
  56.           jz      SHORT Calc           ; done if it is a nul
  57.           stosb                        ; put it in destination if not
  58.           loop    Loop2                ; repeat until done
  59. Calc:
  60.           sub     dl, cl               ; calculate length byte
  61. Done:
  62.           lds     si, EnvDest          ; ds:[si] = length byte
  63.           mov     ds:[si], dl          ; set the length byte
  64.           pop     ds                   ; restore ds
  65.           ret                          ; return to caller
  66. EnvExec   ENDP
  67.  
  68. CODE      ENDS
  69.  
  70.           END
  71.