How do i parse command line arguments. here is the code i have so far




INCLUDE PCMAC.INC

.MODEL SMALL
.586

.STACK 200h
;Stack declaration.
PSP SEGMENT AT 0 ;[USE16 ; TASM 5 only]

ORG 80h
CMDLen DB ?
Command DB 127 DUP (?)
PSP ENDS

.DATA
;;Data segment, data declarations
Prompt1 DB 'My command Tail is : |', '$'

.CODE
EXTRN GetDec:NEAR, GetDDec:NEAR, PutDec:NEAR
EXTRN PutDDec:NEAR, PutHex:NEAR, PutDHex:NEAR
;;Enable use of the I/O subroutines

CmdTail PROC
_Begin ;Segment register initializations
Assume es:PSP

_putStr Prompt1
;call getDec
;call putHEX
mov bl,CmdLen
sub bh,bh ; bx = command length
cmp bx, 126 ; if command line > 126
jle LengthOK
mov bx, 126 ; command length := 126
LengthOK:
mov [command + bx], '$' ; replace CR with $
mov ax, es:[command]
sub al, '0'
mov ah, 0
call putDec
;mov ah, 0
;_putch al
;_putStr command ,es ; Command not in .DATA segment
ASSUME ds : PSP ; For documentation purposes
_putCh '|', 13, 10

_EXIT 0 ;exit to DOS

CmdTail ENDP
END CmdTail ;Entry point for a main program







what i want to do is pass a number at the command line and then convert the whole number to hex. so far all i have been able to do is get one character at a time and convert it form ascii to decimal.

thanks in advance.
Posted on 2004-08-30 14:28:16 by Kel
Try this:
push es

pop ds
xor ax,ax
cwd
mov si,offset command
skipspaces:
lodsb
cmp al,32
jz skipspaces
back:
sub al,'0'
jb finito
cmp al,10
jae finito
imul dx,dx,10
add dx,ax
lodsb
jmp short back
finito:
mov cx,4
digitloop:
rol dx,4
mov al,dl
and al,15
daa ; A-F becomes 10-15
cmp al,16
sbb al,-49 ; 0-9 becomes 30-39, 10-15 becomes 41-46
stosb
loop digitloop
mov al,'$'
stosb
lea dx,[di-5]
mov ah,9
int 21h ; Print string
int 20h ; Exit
Posted on 2004-08-30 16:18:14 by Sephiroth3
please forgive my ignorance but could you explain whats going on?
Posted on 2004-08-30 17:37:54 by Kel