flat assembler
Message board for the users of flat assembler.

Index > DOS > Getting the Command line arguments?

Author
Thread Post new topic Reply to topic
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
Is there a better way to read the command line arguments then the method im trying just by deducing.


Code:
org 256
use16

     mov cx,82h ;load address of first character in Argument in cx
putchar:
   mov dx,[cl]  ;this is the line im not sure about, load address of cx into dx
     mov ah,2   ; call putc
     int 21h    ; putc
     inc cx       ; loop through command line
     cmp cx,90h     ; until 15 characters from argument are read
     ja Done        ;finish looping
     jmp putchar     ; more characters left in arguments, keep reading
     Done:
     mov ah,4Ch ;quit DOS
     int 20h    ;terminate


commandline:   'this well eventually be the string i move the characters read from command line into'            
    


Thank you greatly for any help.
Post 09 Jan 2004, 02:05
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
mov dx,[cl] <- is it some new addresing mode? You should use bx or some index register.
It looks like you are writing com file (there's no MZ format specifer). So you should write it eg. this way:

Code:
org 100h    ;it looks some weird for me if this is in dec Wink
use16
        mov bx, 82h ;load address of first character in Argument in bx, we leave first character - space
putchar:
        mov dx, [bx]  ;bx, si or di, to be fair we should use: mov dl, byte [bx], but putc uses only dl part of dx, so we can simply move whole word.
        mov ah, 2     ; call putc
        int 21h       ; putc
        inc bx        ; loop through command line
        cmp bx, 90h   ; until 15 characters from argument are read
        jna putchar
        ret           ; in com files you can just use ret to leave program                                                                                   
Post 09 Jan 2004, 10:04
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
This works but doesn't. Lol

It works because it gets the command line

But it doesnt because:
look at example outputs of my program "console"

C:\fasmw150>console
Output: " SET BLASTER ="


C:\fasmw150>console and
Output:"ET BLASTER ="

C:\fasmw150>console arguments
Output:"STER=ents"

C:\fasmw150>console longargumentlist
Output:"longargumentlis"

I only want to load the arguments if they've been entered. And I don't want to read the other characters in the PSP besides the arguments......thanks alot Smile
Post 09 Jan 2004, 23:49
View user's profile Send private message Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
Ok i found something that should greatly help Very Happy

Code:
org 100h
use16
mov ax,5053h
int 05h
mov [commandline],ax
mov dx,commandline
mov ah,2
int 21h



       ret

commandline:    

    


I'm sure this is very easy to fix, but i'm finding a great lack of Fasm documentation....But anyways, i heard that argc is stored in CX, and the argv pointer is returned in AX
Post 10 Jan 2004, 00:13
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
WhiteDwarf wrote:
I only want to load the arguments if they've been entered. And I don't want to read the other characters in the PSP besides the arguments......thanks alot Smile

Oh, that's a problem Smile
At 80h there is stored length of arguments. Just check how much you need to read and read 15 characters or less.

Code:
org 100h    ;it looks some weird for me if this is in dec
use16
        mov bx, 80h  ;load address of counter
        mov cl, [bx] ;load counter
        test cl, cl
        jz bye
        dec cl       ;we don't want print EOL, do we?
        inc bx       ;move to first character
        inc bx       ;skip 1 space. I would rather use scasb to skip all spaces
putchar:
        mov dl, [bx]  ;bx, si or di, to be fair we should use: mov dl, byte [bx], but putc uses only dl part of dx, so we can simply move whole word.
        mov ah, 2     ; call putc
        int 21h       ; putc
        inc bx        ; loop through command line
        dec cl
        jz bye        ;if there is no more characters we can leave program
        cmp bx, 90h   ; until 15 characters from argument are read
        jna putchar
bye:
        ret           ; in com files you can just use ret to leave program    


And that, what you find (int 5h) as I know, gets parameters but according to RBIL, parameters of "PSPS is shareware PostScript PrintScreen utility by A.N.D. Technologies" Smile
Post 10 Jan 2004, 13:52
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
So if i wanted to load the parameters into a variable. Is my way the best? or are there interrupts that could ...get the string for me and i'd just have to move it into a variable.
Post 10 Jan 2004, 20:18
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
WhiteDwarf wrote:
So if i wanted to load the parameters into a variable. Is my way the best? or are there interrupts that could ...get the string for me and i'd just have to move it into a variable.

I think I didn't understand. Do you want load whole command line string into variable or do you want to split your command line by space and then those parts move to variables?
If you want to move (or display this string) that's what I modiffied above is what you can use (but it's not optimal). If you want split into variables, you need do it yourself. I don't know any function interrupt that could do this by you, and... I think it's good. I not always want to have splitted this string. Thats asm. You have got more control Smile
Post 11 Jan 2004, 10:15
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
here's my own attempt at it Very Happy *borrowing some of your techniques* just does a size check instead of loading first X characters from argument line.

Code:
org 100h                             ;took your advice lol
use16                           
  org 100h
use16
   mov bx,80h
   mov cl,[bx]
   test cl,cl
   jz NoArguments
   add cx,bx
   inc bx
Again:
   inc bx
   cmp bx,cx
   ja NoArguments
    mov dl,[bx]
    mov ah,2
    int 21h
    jmp Again
NoArguments:
    ret
             


  
    


And here's an argc function i wrote

Code:
org 100h
use16
   mov ax,0
   mov bx,80h
   mov cl,[bx]
   test cl,cl
   jz NoArguments
   dec cl
   add cx,bx
Again:
   inc bx
   cmp bx,cx
   ja NoArguments
    mov dl,[bx]
    cmp dl,20h
    jne Again
    inc ax
    jmp Again
 NoArguments:
    mov dx,ax
    add dl,'0'
    mov ah,2
    int 21h
    ret
                                
    


Tell me what you think. Smile
Post 12 Jan 2004, 03:26
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
Nice, but if there is more then one space between parameters then it'll count wrong. A little shorter version without this error:

Code:
org 100h
use16
   mov dx, '0'
   mov di, 80h
   mov cl, [di]
   xor ch, ch
   inc di
   inc cx
   mov al, 20h
Again:
   repe scasb           ;skip leading spaces
   test cx, cx          ;test if there is no more arguments
   je NoArguments
   inc dx               ;inc arguments count
   repne scasb          ;skip parameter
   jmp Again

NoArguments:
    mov ah,2
    int 21h
    ret    


Ofcourse if there is more then 9 parameters it will show some characters other then digit Smile
I think you should read a little about instructions, which deals with strings (lods, movs, scasb, cmps etc.). It'll help you write simpler routines.
Post 13 Jan 2004, 09:36
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
Aight thanks, i'll have to look into that. Would you mind if i uploaded your code to my site for demonstrative purposes? Smile
Post 14 Jan 2004, 03:20
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
Do with it whatever you want Smile
Post 14 Jan 2004, 15:46
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
Code:
       org 100h
    use16
       MOV     SI,80h          ;ARGC cmnd line count byte adr in PSP
       LODSW                   ;inc SI=82h now = ARGV
      OR      AL,AL           ;check for AL=0
     JZ      NOinput
     MOV     CL,AL
       XOR     CH,CH
       JCXZ    NOinput         ;another type of check if AL=0
      DEC     CX              ;off by 1 ? ARGC counts space at [81h]
      JZ      NOinput
     CMP     AL,5            ;decide if your program requires a minimum of input
 JB      NOinput         ;print error message AH=9 DS:DX=msg adr INT 21h stuff

       MOV     DI,BUFFER       ;store WORD offset adr of each input at ES:DI
   MOV     AX,SI           ; 82h = first adr
   STOSW                   ; save adr
PARCE:
    LODSB                   ;get byte into AL from DS:SI & INC SI
       CMP     AL,13           ;CR=13 end of command line
  JZ      EOLcmnd         ;redundant with CX=LOOP count
       CMP     AL,'a'
    JB      NOlowr
      CMP     AL,'z'
    JA      NOlowr
      OR      AL,11011111b            ;clear bit-5 = alph to UPPER case
NOlowr:
    CMP     AL,32           ;space=32
   JNZ     NOspac
      MOV     AX,SI
       STOSW                   ; put address of next input into BUFFER
     XOR     AL,AL           ;AL=0=NUL=ASCIIZ file name, alter the command line in the PSP = ok.
NOspac:
  MOV BYTE [SI-1],AL      ;write un/altered byte to were is was in PSP
        LOOP    PARCE           ;use CX to loop (choose one)
        JMP BYTE PARCE          ;use CR check to end loop, JMP SHORT PARCE

;program code here
;exit code here

BUFFER: ;end of .COM code label, starts 60k+? usable buffer.

    


;untested code above, duplicates a bunch of junk,
:shows different ways to deal with input,
;needs to be debuged & converted to your needs.

;here's something I just discovered:

BUFFER: ;end of .COM code label
BUFsize = 0xFF00-$
;BUFsize is the size of the usable buffer between the codes end & the stack = sizeof 0xFF
;a .COM loads to 0x10000 bytes, the .COM code is small, it needs a stack space reserved
;from 0xFFFE on up to the code & 100h is enough.
;BUFsize is usefull for loading files into your buffer.

I hope that helps some how.

Bitdog
Post 18 Jan 2004, 16:38
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.