Note: This is the June 17, 2006 capture of http://bentong.topcities.com/comp/progs/asm/comargs.htm from the Wayback Machine. This was uploaded to the reloaded ISLESV.NET on June 22, 2023.
; COMARGS.ASM: Returns first command-line argument passed to program.
; Start with a dash, only 13 chars.
; This file Copyright (C) 2004-2005 by Vincent "Bentong" S. Isles
; http://bentong.topcities.com
; bentong_isles@yahoo.com
.MODEL SMALL
.CODE
ORG 100H
ENTRY: JMP REAL_START
MPARA DB 'Passed parameter is $'
NOPARA DB 'No parameters.$'
EMSG DB 'Usage: PARA -parameter$'
REAL_START:
MOV BL,ES:[80H] ; ES,CS,DS, whatever: COM only takes
; one segment. We'll use ES cOZ for
; EXE it points to PSP starting address
CMP BL,0 ; are there any characters?
JZ NO_PARAM ; we have no characters
MOV CL,2 ; we'll look for two '-'
MOV SI,81H ; point SI to start of CTL
SKIP_BLANKS: ; start of process
MOV BL,ES:[SI] ; get a character
INC SI ; increment first
CMP BL,20H ; blank char, get another
JZ SKIP_BLANKS
CMP BL,0DH ; carriage return
JZ NO_PARAM ; no parameters
CMP BL,'-' ; daz wat we looking 4
JZ GET_PARA
LEA DX,EMSG
MOV AH,9
INT 21H
JMP GOODBYE
GET_PARA:
MOV [SI+12],' $' ; str end char
; just to make dear TASM happy
LEA DX,MPARA ; "Passed parameter is "
MOV AH,9
INT 21H
MOV DX,SI ; beginning of first para
MOV AH,9
INT 21H
JMP GOODBYE ; let's get out
NO_PARAM: ; we got no parameter
LEA DX,NOPARA ; no parameter string
MOV AH,9 ; disp str
INT 21H
GOODBYE: ; let's get out
INT 20H
END ENTRY