i fetch the argv list i want 2 print the argv[0] like in c
plz help me how i print the arglist mainly i want argv[0]



STACK_SEG SEGMENT PARA STACK 'STACK'
  DB 1024 DUP(' ')
STACK_SEG ENDS

DATA_SEG SEGMENT PARA 'DATA'
     
DATA_SEG ENDS

CODE_SEG SEGMENT PARA 'CODE'
   
    ASSUME SS:STACK_SEG,DS:DATA_SEG,CS:CODE_SEG
   
   
    MAIN PROC FAR
   
        PUSH BP
        MOV BP,SP
        PUSH SI
        MOV SI,WORD PTR    ;ARGV
       
       
    PRINTARGV:
       
       
       
       
        POP SI
        POP BP
       
    EXIT:
        MOV AX,4C00H
        INT 21H
       
    MAIN ENDP
   
   
CODE_SEG ENDS
 
  END MAIN
Posted on 2006-07-19 05:14:45 by sihotaamarpal
This is in Nasm format, but I also have it in Masm.. It works in a DOS Window.

; Test 3 - Read the PSP , Save it into a buffer and print it

bits 16
org 0100h

section .code

start:

; Find the PSP - Bx = PSP address

Find_PSP:
mov ax, 5100h ; Find the PSP
int 21
;
add bx, 80h ; Where the Command Line tail resides
mov ax, ; Length of Parameter string
cmp al, 00 ; Anything there?
jnz Copy_Name ; Yes, Jump over the error string
;
mov dx,  Not_There ; Error string
jmp Print ; Print it and exit
;
; Copy the filename into the buffer. Si and Di move the string,  Cx is the counter, Al holds the parameter length

Copy_Name:
cld ; Si and Di + 1, Cx - 1
mov ah, 00 ; clear the upper byte
dec al ; Skip over the space
mov cx, ax ; Length of string
mov si, 0082h ; Start of parameter string
mov di,  Address ; Buffer to save parameters in
rep movsb ; Copy the parameters to the buffer
;
mov si, Tail ; Add a '$' to the end of the string
mov cx, 03 ; 3 bytes to add
rep movsb
;
mov dx,  Address ; Address of our Message
;
Print:
mov ah, 09 ; DOS - Print a string
int 21h
;
mov ah, 4Ch ; DOS - Program termination. Error number (if any) in Al
int 21h

segment .data

Not_There db "The command line is empty", 0Dh, 0Ah, 24h ; Error string
Tail db 0dh, 0Ah, 24h

section .bss

; The command tail is 127 bytes long
Address: resb 127
Posted on 2006-10-25 21:09:43 by ZaneL
sihotaamarpal,
argv() is something the C runtime does for you before your code runs, so you will have to scan the command tail yourself.

ZaneL,

Find_PSP:
  mov  ax, 5100h      ; Find the PSP
  int  21

puts the segment of the PSP in BX, so you will need something like this

  mov es,bx
  mov bx,80h

and use ES:BX to access the command tail.
Posted on 2006-10-25 22:20:53 by sinsi
If you want the name of the program being executed, then you will also need to get the environment block segment. The program name comes after the environment string list.
Posted on 2006-10-25 23:44:22 by tenkey
You can find this code in the OASML library located here: http://www.asmcommunity.net/board/index.php?topic=25410.0.

Here is the direct link to download the library: http://www.asmtrauma.com/Downloads/AsmLibs/OASML1.0.ZIP


The procedure that you need is called and is located in the "DOS" unit of the library. The procedures are fully commented but you can ask any further questions here if you want. However, if you merely need to retrieve the full path to your application as in argv[0], you could use the in the OASML library which is located in the "DOS" unit, too.
Posted on 2006-10-26 02:39:45 by XCHG