home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / environm / prenv.asm < prev    next >
Assembly Source File  |  1988-09-05  |  3KB  |  104 lines

  1. comment    |
  2.  
  3.     This program demonstrates how to read this program's copy of the
  4.     parent's environment created by COMMAND.COM ... For DOS Ver 3.x, the
  5.     fully justified path name of this program will also be displayed.
  6.  
  7.     The environment consists of null-terminated ASCII strings (ASCIIZ),
  8.     with the entire list terminated by another null. A 2-byte entry at
  9.     offset 2Ch in the program's program segment prefix (PSP) contains the
  10.     segment of the copy of the environment. The code commenting, wording
  11.     of printing messages and some of the code itself have been changed in
  12.     a number of places.
  13.  
  14.     Written for MASM 5.0 by Hardin Brothers for PCResource. The original
  15.     appeared in the April 1988 issue of their magazine. Entire contents of
  16.     the April 1988 issue (C) Copyright 1988 by
  17.                 IDG Communications/Peterborough, Inc.
  18.  
  19.     Hardin Brothers is a freelance programmer and technical writer. Write
  20.     to him at 280 N. Campus Ave., Upland, CA  91786. Enclose a self-
  21.     addressed, stamped envelope for a reply.
  22.  
  23.     |
  24.  
  25. LF    equ    0Ah    ; linefeed char
  26. CR    equ    0Dh    ; carriage return char
  27. STDOUT    equ    1    ; standard output device
  28.  
  29. EXIT    macro    val
  30.     mov    AH, 4Ch        ; INT 21h service 4Ch: exit from program
  31.                 ; also returns a value. replaces old INT 20h.
  32.     mov    AL, val        ; return value byte
  33.     int    21h
  34.     endm
  35.  
  36.     .MODEL    SMALL
  37.     .STACK
  38.  
  39.     .CODE
  40.  
  41. start:    cld            ; clear direction flag:
  42.                 ;   search from lowmem to highmem
  43.     mov    DS, ES:[2Ch]    ; point DS to environment copy
  44.     mov    ES, ES:[2Ch]    ; point ES there, too
  45.     mov    AH, 02h        ; INT 21h service 02h: write a char to stdout
  46.     mov    DL, CR
  47.     int    21h
  48.     mov    AH, 02h
  49.     mov    DL, LF
  50.     int    21h
  51.     mov    DI, 0        ; set pointer offset from ES
  52.     mov    CX, 7FFFh    ; max. environment size = 32768 bytes
  53.     mov    BX, STDOUT    ; write to standard output device
  54.  
  55. lp:    test    byte ptr ES:[DI], 0FFh    ; test for end of list
  56.     jz    cmd_nam        ; skip to cmd_nam if so
  57.     sub    AL, AL        ; set AL = 0
  58.     mov    DX, DI        ; put start offset in DX
  59.     repne    scasb        ; search for null char
  60.     push    CX        ; save byte count
  61.     mov    CX, DI        ; get tail + 1
  62.     sub    CX, DX        ; set CX to string length
  63.     mov    AH, 40h        ; INT 21h service 40h: write to file/device
  64.     int    21h
  65.     mov    AH, 02h
  66.     mov    DL, CR
  67.     int    21h
  68.     mov    AH, 02h
  69.     mov    DL, LF
  70.     int    21h
  71.     pop    CX        ; restore byte count
  72.     jmp    lp        ; continue search
  73.  
  74. cmd_nam:
  75.     mov    AH, 30h        ; INT 21h service 30h: get DOS version number
  76.     int    21h
  77.     cmp    AL, 3        ; is this Ver 3.x ?
  78.     jb    endit        ; skip to endit if not
  79.     inc    DI        ; addr ES:DI points to word 0001h flag
  80.  
  81.     cmp    word ptr ES:[DI], 1    ; check flag value
  82.     jne    endit        ; skip to endit if unflagged
  83.     add    DI, 2        ; addr ES:DI points to head of name
  84.     mov    DX, DI        ; save addr of head
  85.     sub    AL, AL        ; set AL = 0
  86.     mov    CX, 0FFh    ; set search until end
  87.     repne    scasb        ; search for null char
  88.     mov    CX, DI        ; get addr of tail
  89.     sub    CX, DX        ; set CX to string length
  90.     mov    BX, STDOUT    ; write to stdout
  91.     mov    AH, 40h
  92.     int    21h
  93.  
  94. endit:    mov    AH, 02h
  95.     mov    DL, CR
  96.     int    21h
  97.     mov    AH, 02h
  98.     mov    DL, LF
  99.     int    21h
  100.     EXIT    0        ; normal termination
  101.  
  102.     end    start
  103.  
  104.