alanr@tekigm2.MEN.TEK.COM (Alan Rovner) (04/17/89)
Can I access DOS command line arguments through assembly language? This would be the equivalent to using argc and argv in C. I would appreciate a short example if possible. Thanks, Al Rovner Tektronix Inc. Vancouver, Wash.
jmv@sppy00.UUCP (Jim Vickroy) (04/18/89)
In article <4496@tekigm2.MEN.TEK.COM> alanr@tekigm2.MEN.TEK.COM (Alan Rovner) writes: => =>Can I access DOS command line arguments through assembly language? =>This would be the equivalent to using argc and argv in C. I would =>appreciate a short example if possible. Yes you can. The command line parameters are passed to you through the PSP, specifically at offset 81 hex. Located at offset 80 hex is a byte which is the length of the parameter string. The command line is delivered intact: If you launched a program: MYPROG -a -b -cde filename the PSP would contain this information: Offset Contents ======= ========================================= 80h 13h 81h-94h "-a -b -cde filename" (excluding the "'s) Sorry, I don't have source right here to include. If you have problems, e-mail a request and I'll try to round up the appropriate code segment.. Good luck.... jim -- ============================================================================== :::: ::: :: :: : : Jim Vickroy |OC| ||| || || | | Technical Services Department |LC| ||| || || | | Online Computer Library Center, Inc. :::: ::: :: :: : : Dublin, Ohio ------------------------------------------------------------------------------ UUCP: {att|pyramid|killer}!osu-cis!sppy00!jmv domain: jmv@sppy00.uucp USSNAIL: 6565 Frantz Rd., Dublin, Ohio 43017-0702 ------------------------------------------------------------------------------ "They came. They saw. They kicked butt." -Nike shoe ad ==============================================================================
pozar@hoptoad.uucp (Tim Pozar) (04/19/89)
In article <4496@tekigm2.MEN.TEK.COM> alanr@tekigm2.MEN.TEK.COM (Alan Rovner) writes: > >Can I access DOS command line arguments through assembly language? >This would be the equivalent to using argc and argv in C. I would >appreciate a short example if possible. > I wrote this for getting the switch chars in assembly. At this time I think this will only work if you compile this to .COM programmes due to .EXE's header junk. I could be wrong. It's been a while since I hack on this stuff... Tim --- cut here --- page 55,132 title 'PROGRAMME -- Description.' ; FALSE EQU 0 TRUE EQU NOT FALSE eom equ 0h ;End of string char (did you think I was going to ;use '$' ?!!!) DosCall equ 021h ;Interupt number for dos calls ; lf equ 0ah ;Equates here cr equ 0dh ; prognam segment public public putout ; assume cs:prognam,ds:prognam,ss:prognam org 80h psiz db ? pstng db ? org 100h ; start: mov ax,cs mov ds,ax mov ss,ax mov sp,offset stack ; begin: ;beginning of programme mov dx,offset signon_msg call pstring mov al,psiz ;how many char are on the command line mov switch_num,al cmp al,0 jz help ;if there is none, display help msg cmp al,1 jnz nohelp ;if there is just one, display help msg ;else skip over and start parsing help: mov dx,offset help_msg call pstring jmp exit nohelp: sub cx,cx mov cl,switch_num mov si,offset pstng ;start of command string cld ; lp1: lodsb cmp al,switch_char1 jz tswtch cmp al,switch_char2 jz tswtch jmp lpend tswtch: push ax mov ax,TRUE mov switch_rcv,ax pop ax dec cx ;test what switch char is out there lodsb ; tog_ins1: cmp al,"p" jz p_set cmp al,"P" jnz defalt p_set: ;set p_flag (used later on in the programme ;to know that a switch was used. mov p_set,TRUE jmp lpend ; defalt: ;Did not reconize this char as a valid command. push ax mov dx,offset duh_msg call pstring pop ax call pchar mov al,'.' call pchar jmp help lpend: loop lp1 ; lpfin: mov ax,switch_rcv ;did we get a valid switch char some cmp ax,TRUE ;where in there? jz main mov dx,offset no_swtch_msg ;if not, bomb out call pstring jmp help ; ; M A I N ; main: ; Programme goes here... exit: mov ah,4ch ;termination of programme int 21h ; pstring proc near ;SAMPLE CALL TO PSTRING ;mov dx,offset anounc ;point to address of message "anounc" ;call pstring ;display anounc ; mov bx,dx pmore: mov al,[bx] cmp al,eom jz pfin call pchar inc bx jmp pmore pfin: ret ; pstring endp ; pchar proc near ;sends one char to the console mov ah,2 mov dl,al int DosCall ret ; pchar endp putout proc near ; putstart: mov dx,msr in al,dx and al,80h ;is there a carrier? jz putdone ;if not, we're done. mov al,[si] ;get char from string cmp al,eom ;is this the end of the string? jz putdone ;if so, we're done. mov dx,0 mov ah,1 int 14h ;send 'bye' string to COM1 mov dl,[si] call pchar ;echo 'bye' string to stdout inc si ;point to the next char jmp putstart ;and do it again putdone: ret ; putout endp db 10 dup ('stack ') ;room for stack stack label byte ;top of stack no_swtch_msg db cr,lf," Did not find the current switch character on the" db cr,lf," command line. Please use either '/' or '-'." db cr,lf,eom duh_msg db cr,lf," Did not reconize the command line switch charater " db eom signon_msg db "PROGRAMME name here". db cr,lf,"Copyright (c) 1987 by T.M. Pozar" db cr,lf,eom help_msg db cr,lf,"Use:" db cr,lf,"PROGRAMME -P" db cr,lf," Where:" db cr,lf," P = Pswitch" db cr,lf,eom ; switch_num db 0 switch_char1 db "-" switch_char2 db "/" switch_rcv dw FALSE ;TRUE = got a valid switch char on the ;command line ; prognam ends end start -- ...sun!hoptoad!\ Tim Pozar >fidogate!pozar Fido: 1:125/406 ...lll-winken!/ PaBell: (415) 788-3904 USNail: KKSF / 77 Maiden Lane / San Francisco CA 94108