Further PC Assembler Sample: Processing the Command Tail
As a further exercise in IBM PC Assembler programming, we examine a simple
program to process the "command tail" as supplied by MS-DOS to all programs.
Although this example is artificially oversimplified compared to "real"
applications, it demonstrates a number of methodologies including how to
access data in an area not pointed to by the DS: register.
The Command Tail
The "command tail" is the string of characters typed on the command line
following the command/program name in an MS-DOS environment.
It is located in the Program Segment Prefix - that 0x100-byte prefix
that precedes all .COM programs (and is a separate segment in .EXE programs).
- Part of the PSP: starts at a byte offset of 0081h from the
start of the PSP.
- Initially DS: and ES: both point to PSP: For .COM programs, the PSP
is part of the only segment; so all segment registers point to it. For .EXE
programs, the PSP is outside of all programmer defined segments.
- Terminated with a "Carriage Return" code: The text of the command
tail ends with a CR character. Alternatively, the length (excluding the
"Carriage Return") is contained in the byte at offset
0080h within the PSP.
Accessing Data Using the ES: Register in a .EXE program
In a typical .EXE environment, the DS: register is modified quite early
in the program to point to a Data segment (a segment containing data values).
BEGIN: MOV AX,DATASEG
In order to access values in the PSP (and particularly in the command tail)
in an .EXE program,
it is necessary to use the ES: register, since the ES: register is the only
thing left which gives the location of the PSP.
MOV SI,81h ;initialize pointer to start of command tail
MOV AL,ES:[SI] ;over-ride default DS: segment usage
The Sample Problem
Display the "words" found on the command tail, one word per line.
The entire sample program can be found at tail.asm.