News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What is this?

Started by vasant, March 30, 2006, 11:57:00 PM

Previous topic - Next topic

vasant

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)

Tedd

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
No snowflake in an avalanche feels responsible.

MichaelW

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]
eschew obfuscation

vasant

First Char is [82h] ?
[81h] ?

MichaelW

The first character is normally the space that follows the program name (required by some programs).




eschew obfuscation

Tedd


  8              9
  123456789ABCDEF0123
   -a -r +h +s T.TXT⌂
No snowflake in an avalanche feels responsible.