flat assembler
Message board for the users of flat assembler.

Index > DOS > How hard is doing command line arguments?

Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2 15 Oct 2006, 21:32
I wanted to see how you would write a special COM that would accept
command line arguments.

So,an example would be a COM named hello.com .

You would type

hello dude

and the program would say

WAZZUP dude

I remember doing just that with argc and argv in C. Is it very hard in ASM?

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 15 Oct 2006, 21:32
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 15 Oct 2006, 21:38
Code:
org 100h

label arguments_length byte at 80h
label arguments_data byte at 81h

        mov     ah,9    ; display string to stdout
        mov     dx,_msg
        int     21h
        mov     ah,40h  ; write file
        mov     bx,1    ; 1 - handle of stdout
        mov     dx,arguments_data
        mov     cl,[arguments_length]
        xor     ch,ch   ; number of bytes to write in CX
        int     21h     ; writing to stdout displays the bytes
        int     20h     ; exit program

_msg db 'WAZZUP',24h    
Post 15 Oct 2006, 21:38
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Oct 2006, 22:09
means, you don't have argc and argv, you just have simple string at CS:81h, whose length is stored in byte at CS:80h
Post 15 Oct 2006, 22:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 15 Oct 2006, 23:26
It's better to say PSP:80h - in case of MZ EXE it's also this way, though PSP is not necessarily CS.
Post 15 Oct 2006, 23:26
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Oct 2006, 23:38
well.. it is more general, but less understandable. depends on which of these two you (or reader) prefers
Post 15 Oct 2006, 23:38
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 16 Oct 2006, 05:43
Thanks! That helped me do this!

Code:
org 256
mov ah,9
cmp byte[128],0
je p1
jmp p2
p1:
mov dx,n
int 33
jmp p3
p2:
mov dx,y
int 33
mov ah,64
mov bx,1
mov cl,[128] ;offset that says how many bytes the argument is
xor ch,ch ;set ch to 0 so it won't interfere with the value of cx
mov dx,129 ;space followed by arguments
int 33
mov ah,9
mov dx,a
int 33
p3:
int 32
n db 'What is your name? You must tell me from the command line!',36
y db 'Hello',36
a db ', you are awesome!!!',36
    
Post 16 Oct 2006, 05:43
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 17 Oct 2006, 03:19
Is it the same with Windows apps as well, making a call from CS:81h for the command line, that is?
Post 17 Oct 2006, 03:19
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 17 Oct 2006, 14:57
in Windows you use the GetCommandLine function to get a pointer to the command line. It has the program name in it as well as the arguments, though.
Post 17 Oct 2006, 14:57
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1403
Location: Piraeus, Greece
Picnic 23 Sep 2007, 14:37
Hello all,
I want to take only one parameter, remove head-tail spaces, and store on a buffer as a null terminated string. Length on cl.
I wrote few lines below, (running xp console), am i ok?
Code:
    org 100h

    mov si,82h
    mov di,par
    xor ch,ch
    mov cl,[si-2]
    jcxz exit
@@:
    lodsb  
    cmp al,20h
    jz @b 
    xor cl,cl  
    dec si
@@:
    lodsb
    stosb    
    cmp al,0dh
    jz @f
    cmp al,20h
    jz @f
    inc cl
    jmp @b
@@:
    mov byte [di],0
    
    
    exit:
    int 20h
     
    par db 128 dup ?
    

_________________
Hobby BASIC Interpreter
Post 23 Sep 2007, 14:37
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 07 Oct 2007, 02:58
You could use WDOSX as a DOS extender. If you use NASM's RDOFF (maybe other? formats), it sets up argc, **argv for you.
Post 07 Oct 2007, 02:58
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.