[comp.sys.ibm.pc] Accessing the command line

831059l@aucs.UUCP (STEVEN LUCIEN LANGLOIS) (11/30/87)

	Does anybody know how to access the command line from assembler?
I heard that it was stored at 80h but it was not recommended to use
this because it was old CP/M. Thanks for any help.


Steven Langlois Acadia Univ. Wolfville NS Canada B0P1X0 
UUCP:{uunet|watmath|utai|garfield}dalcs!andedandeda

mrk@gvgspd.UUCP (Michael R. Kesti) (12/01/87)

In article <605@aucs.UUCP> 831059l@aucs.UUCP (STEVEN LUCIEN LANGLOIS) writes:
>
>	Does anybody know how to access the command line from assembler?
>I heard that it was stored at 80h but it was not recommended to use
>this because it was old CP/M. Thanks for any help.

Not only is this the correct method, but, to my knowledge, the only method!
I include here a small program I wrote when I was first exploring this
issue that demonstrates how to access this data.

------------------------ cut here for parmecho.asm ----------------------
	.xlist
	if1
	%out	PARMECHO.ASM
	endif
	if2
	%out	*** PASS 2
	endif
	.list
	name	PARMECHO
	title	PARMECHO
	subttl	ECHOS COMMAND LINE PARAMETERS
	page	,132

; ************************************************************************
; **									**
; ** filename:	parmecho.asm						**
; **									**
; **	Echos any supplied parameters and the quantity of characters.	**
; **									**
; ************************************************************************

nul		equ	00H	; ^@
lf		equ	0AH	; ^J
cr		equ	0DH	; ^M

dos_term	equ	20H	; dos program termination interrupt
dos_func	equ	21H	; dos function interrupt
write		equ	40H	; write file/device dos function

code	segment public
	assume	cs:code,ds:code

	org	100H			;

pgm:
	jmp	start			; don't execute data


; data storage

msg	db	' CHARACTERS',
newline	db	cr,lf,nul


start:
	mov	dl,0			; initialize decimal counter
	mov	si,80H			; point to parameter character count
	mov	ch,0			;
	mov	cl,[si]			; load parameter character count
	inc	si			; point to parameters
	jcxz	print_count		; zero characters? -  yes - print count

	mov	al,'>'			; no - load delimiter
	call	wr_std			; write character to standard output

print_chars:
	mov	al,[si]			; load next character
	call	wr_std			; write character to standard output
	mov	al,dl			; load counter
	add	al,1			; advance
	daa				; adjust
	mov	dl,al			; store
	inc	si			; point to next character
	loop	print_chars		; done? - no - continue

	mov	al,'<'			; yes - load delimiter
	call	wr_std			; write character to standard output
	lea	si,newline		; point to string
	call	wr_str			; write string to standard output

print_count:
	mov	al,dl			; load decimal counter
	mov	cl,4			;
	rol	al,cl			; swap nibbles
	and	al,0FH			; isolate tens - zero tens?
	jz	print_ones		; yes - print ones

	or	al,'0'			; no - convert to ascii
	call	wr_std			; write character to standard output

print_ones:
	mov	al,dl			; load decimal counter
	and	al,0FH			; isolate ones
	or	al,'0'			; convert to ascii
	call	wr_std			; write character to standard output

	lea	si,msg			; point to string
	call	wr_str			; write string to standard output
 	int	dos_term		; terminate program
	page
; ************************************************************************
; **	function: write string to standard output			**
; **	input: si = string pointer					**
; **	uses: none							**
; **	exit: none							**
; **	calls: wr_std							**
; ************************************************************************

wr_str:
	push	ax			;
	push	si			; save registers

wr_str_05:
	mov	al,[si]			; load character
	cmp	al,0			; terminator?
	je	wr_str_10		; yes - done

	call	wr_std			; no - write character to standard output
	inc	si			; advance pointer
	jmp	wr_str_05		; continue

wr_str_10:
	pop	si			;
	pop	ax			; restore registers
	ret				;
	page
; ************************************************************************
; **	function: write character to standard output			**
; **	input: al = character						**
; **	uses: cs:80H for DTA						**
; **	exit: none							**
; **	calls: none							**
; ************************************************************************

wr_std:
	push	ax			;
	push	bx			;
	push	cx			;
	push	dx			;
	push	di			; save registers
	mov	ah,write		; indicate write function
	mov	bx,1			; load standard output file handle
	mov	cx,1			; indicate number of bytes to write
	mov	dx,80H			;
	mov	di,dx			; point to DTA
	mov	[di],al			; write character to DTA
	int	dos_func		; output character
	pop	di			;
	pop	dx			;
	pop	cx			;
	pop	bx			;
	pop	ax			; restore registers
	ret				;

code	ends

	end	pgm
-------------------------- end of parmecho.asm --------------------------

-- 
====================================================================
Michael Kesti  Grass Valley Group, Inc. | "Initiative comes to those
P.O. Box 1114  Grass Valley, CA  95945  | who wait."
UUCP:	...!tektronix!gvgpsa!gvgspd!mrk |    - Alex "655321" Delodge