home *** CD-ROM | disk | FTP | other *** search
- .model small
-
- .data
- EXTERN PSPSeg: WORD
- CRLF db 13,10
- no_params_msg db 'There are no parameters on the command line!',0
- done_msg db 'Program terminated normally.',0
-
- .code
-
- EXTERN ParamStr : NEAR
- EXTERN ParamCount : NEAR
- ;*******************************************************************
- ; void WriteLn( void );
- ; Writes a CR/LF pair to StdOut.
- ; Assumes ds points to @data. Preserves all registers
- ;*******************************************************************
- WriteLn PROC USES ax bx cx dx
- mov dx, offset CRLF
- mov cx, 2
- mov ah, 40h
- mov bx, 1
- int 21h
- ret
- WriteLn ENDP
-
- ;*******************************************************************
- ; void PrintStr( char far *lpStr );
- ;
- ; Sends a zero-terminated string to StdOutput, followed by a CR/LF
- ; Uses register calling convention: lpStr is expected in dx:ax!
- ; Preserves all registers, expects ds pointing to @data.
- ;*******************************************************************
- PrintStr PROC USES ax bx cx dx
- push ds ; save ds
- mov ds, dx ; point ds:dx to string (pointer in dx:ax)
- ASSUME ds:nothing
- mov dx, ax
- sub cx, cx ; initialize counter to zero
- mov bx, dx ; point bx to start of string
- ; determine length of string, put length into cx
- find_eos:
- cmp byte ptr[bx], 0 ; end of string reached?
- je @F ; if yes, exit loop
- inc cx ; else inc counter
- inc bx ; address next char
- jmp short find_eos ; and check it
- @@:
- ; write the determined number of charcters to StdOut (if there are any)
- jcxz string_empty
- mov ah, 40h ; DOS write to file/handle
- mov bx, 1 ; StdOut handle
- int 21h ; execute
- string_empty:
- pop ds ; restore ds
- ASSUME ds:@data
- call WriteLn ; write a cr/lf to stdout
- ret
- PrintStr ENDP
-
- ;***********************MAIN**************************
- .STARTUP
- mov PSPSeg, es ; save the PSP segment
- ; FOR i:= 1 TO ParamCount DO BEGIN
- ; lpStr:= ParamStr( i );
- ; PrintStr( lpStr ):
- ; END;
- call ParamCount ; return count of parameters in ax
- mov cx, ax ; move it to cx
- jcxz no_params
- xor ax, ax ; use ax as index variable
- params_loop:
- inc ax
- push ax ; save index, ax will be destroyed by call
- call ParamStr ; return pointer to parameter in dx:ax
- call PrintStr ; print it
- pop ax ; restore index
- loop params_loop ; loop if more parameters
- jmp done ; jump to exit
-
- no_params: ; If no parameters, give a message
- mov dx, ds
- mov ax, offset no_params_msg
- call PrintStr
- done:
- mov dx, ds ; give a termination message
- mov ax, offset done_msg
- call PrintStr
- .EXIT 0
- END