The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: vasant on March 30, 2006, 11:57:00 PM

Title: What is this?
Post by: vasant on March 30, 2006, 11:57:00 PM
Like:   c:\attrib.exe -a -r +h +s T.TXT

"-a -r +h +s T.TXT" < What is its name?
If I want input string from Dos command.
How I code?

if I want know about length , how I code?

Thank you.

(Masm 6.13)
Title: Re: What is this?
Post by: Tedd on March 31, 2006, 12:37:42 PM
Usually referred to as "command-line arguments".
But you usually have to get the whole string, and then find the arguments yourself.
So, the first step is to get the address of the string. Luckily this is as simple as "mov si,81h" -- that is where the command-line string starts, and it ends with a 0Dh byte (13).
Then you have to search through the string and extract the arguments, usually you can just skip spaces and each argument starts after the space(s).
The length is supposedly stored at [80h] but it seems unreliable, but you can get thel ength of the string yourself by counting the bytes until the 0Dh :wink
Title: Re: What is this?
Post by: MichaelW on March 31, 2006, 01:17:29 PM
Hi vasant,

You are still working on this after 5 months?

The attachment contains an example that just reads and displays the command line.


; --------------------------------------------------------------
; This program reads and displays its command line, then waits
; for a key press before terminating.
;
; The program loader sets ES and DS to the segment address of
; the PSP. The startup directive sets DS (and SS) to DGROUP,
; but leaves ES set to the PSP. The byte at offset 80h in the
; PSP contains the length of the command line including the
; leading space but not including the terminating CR (CR =
; carriage return, ASCII code 0dh). This code ignores the
; length byte and scans for the CR.
; --------------------------------------------------------------
    .model small
    .386
    .stack
.data
.code
.startup
    mov   bx, 81h
  @@:
    mov   dl, es:[bx]
    inc   bx
    mov   ah, 2   ; DOS Display Character function
    int   21h
    cmp   dl, 0dh
    jne   @B
    mov   ah, 2
    mov   dl, 0ah ; Display linefeed to move cursor to next line
    int   21h
    mov   ah, 0   ; BIOS Get Keystroke function
    int   16h     ; BIOS will wait for key press
.exit
end


The attachment also includes a batch file (try.bat) that runs the program and passes it a command line, and another batch file (dbg.bat) that will load the program with a command line into DEBUG. The purpose of this batch file is to allow you to see the command line in memory. To do this, after DEBUG starts enter

d es:80

at the DEBUG prompt. When you are finished, enter q at the DEBUG prompt to quit.




[attachment deleted by admin]
Title: Why start at 81h?
Post by: vasant on April 02, 2006, 12:07:35 PM
First Char is [82h] ?
[81h] ?
Title: Re: What is this?
Post by: MichaelW on April 02, 2006, 01:41:01 PM
The first character is normally the space that follows the program name (required by some programs).




Title: Re: What is this?
Post by: Tedd on April 03, 2006, 11:15:31 AM

  8              9
  123456789ABCDEF0123
   -a -r +h +s T.TXT⌂