Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : PROGNAME.ASM

 
Output of file : PROGNAME.ASM contained in archive : PCTJ8805.ZIP
comment | _progname.asm Written by Martin Stitt

This function extracts from the environment the name of the currently
executing program, including the path used to load it.

Written for Microsoft C small memory model, but can be
modified for other models, compilers and languages.

Function declaration: int progname(char *namestr)
Returns length of namestr.
|

_text segment word public 'code'
assume cs:_text
public _progname

_progname proc near
push bp ; standard C entry sequence
mov bp,sp

push si
push di
push es
cld ; insure forward searching
mov ah,62h ; get PSP segment address
int 21h
mov es,bx
mov es,es:[2ch] ; get seg of environment from PSP
xor di,di ; start at offset zero
xor al,al
mov cx,0ffffh

gp1: repne scasb ; find the end of each env string
cmp byte ptr es:[di],0 ; end of environment?
jne gp1 ; no: loop thru next string
add di,3 ; yes: point to start of name

mov si,di ; save start addr of name
repne scasb ; and then find its end
mov cx,di
sub cx,si ; cx = length of string + 1
push cx ; save it for return value

mov ax,ds ; set up seg regs for string move
mov bx,es
mov ds,bx ; ds:si -> start of path string
mov es,ax ; es:di -> caller's receiving addr
mov di,[bp+4]
rep movsb ; move the path string, incl. null
mov ds,ax ; restore data segment

pop ax ; get length of string
dec ax ; adjust for terminator

pop es
pop di
pop si
pop bp
ret
; ret 2 ; use this if your caller does not
; remove parms from stack
_progname endp
_text ends
end


  3 Responses to “Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : PROGNAME.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/