home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / 80x0393.zip / MYPATH.ASM < prev    next >
Assembly Source File  |  1993-03-30  |  3KB  |  84 lines

  1. ;*** MYPATH.ASM - Written by Dave M. Walker @ 1:396/1
  2. ;*** Released into the public domain with no reservations.
  3.  
  4.                 IDEAL
  5.                 MODEL   TINY
  6.  
  7.                 DATASEG
  8. PathBuffer      db      128 dup (?)
  9.  
  10.                 CODESEG
  11.                 ORG     0100h
  12.  
  13. EnvSeg          EQU     002Ch
  14.  
  15. Start:          mov     bx,OFFSET PathBuffer    ;Call our routine
  16.                 call    GetPathName
  17.                 mov     si,bx                   ;Print the path
  18.                 call    DispString
  19.                 mov     ax,4C00h                ;Exit
  20.                 int     21h
  21.  
  22. PROC            DispString
  23. DispStringLoop: mov     dl,[si]
  24.                 inc     si
  25.                 cmp     dl,0
  26.                 je      DispStringExit
  27.                 mov     ah,2
  28.                 int     21h
  29.                 jmp     DispStringLoop
  30.  
  31. DispStringExit: ret
  32. ENDP
  33.  
  34. ;***************************************
  35. ;* Find pathname at end of environment
  36. ;* Entry: DS:BX = Buffer
  37. ;* Exit : Pathname copied in the format
  38. ;*        "D:\PATH\"
  39. ;* Regs : None
  40. ;* Note : Requires DOS 3 or higher
  41. ;***************************************
  42. PROC            GetPathName
  43.                 push    ax cx si di ds es       ;Save modified regs
  44.  
  45.                 mov     es,[cs:EnvSeg]          ;Point ES:DI to EnvSeg:0000
  46.                 xor     di,di
  47. FindEnvEnd:     inc     di
  48.                 cmp     [WORD es:di],0          ;Two NULLs means end of env.
  49.                 jne     FindEnvEnd
  50.                 add     di,4                    ;Skip NULLs & trail counter
  51.                 mov     si,di                   ;Save pointer
  52.  
  53. ;*** Find end of pathname (null byte)
  54.                 mov     cx,0FFFFh               ;Set CX to a safe limit
  55.                 cld                             ;Search forward
  56.                 repne scasb
  57.                 sub     di,2                    ;Backup to end of string
  58.  
  59. ;*** Find last backslash to strip filename.ext
  60.                 mov     al,'\'
  61.                 std                             ;Search backward
  62.                 repne scasb
  63.                 inc     di                      ;Include last backslash
  64.  
  65. ;*** Copy pathname into buffer
  66.                 mov     cx,di                   ;Count = (end - start) + 1
  67.                 sub     cx,si
  68.                 inc     cx
  69.                 mov     di,bx
  70.                 push    ds                      ;Swap ES & DS for block move
  71.                 push    es
  72.                 pop     ds
  73.                 pop     es
  74.                 cld
  75.                 rep movsb
  76.                 xor     ax,ax                   ;Terminate with NULL
  77.                 stosb
  78.  
  79.                 pop     es ds di si cx ax       ;Recover caller's regs
  80.                 ret
  81. ENDP
  82.  
  83.                 END     Start
  84.