This example shows how to use the macros that use the command line processing modules in the m64lib library. The design is a space delimited set of command line arguments where text with spaces can be used when enclosed by double quotes.
EXAMPLE appname one "two 2" three four "the number 5" 6 seven eight
This is the example code. You allocate 2 QWORD values, either LOCAL or in one of the .DATA sections, call the "CmdBegin" macro using the two arguments. When the macro returns, you have a pointer to a QWORD array of the arguments on the command line and importantly, the argument count.
As the pointer array is allocated memory, you must not go past the last array member or you will get a paging fault. The design does not impose an argument limit but a normal command line length will impose a limit from the command line. It is possible to set very long command lines from CreateProcess and this system will handle large counts but it would be an unusual task to perform this and would probably be a form of exploit.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
USING r12,r13
LOCAL parr :QWORD
LOCAL acnt :QWORD
SaveRegs
; --------------------------------------------
; get command line pointer array and arg count
; --------------------------------------------
CmdBegin parr,acnt ; start here
; -----------------------------------
; loop through command tail arguments
; -----------------------------------
mov r12, parr ; load array pointer into r12
mov r13, acnt ; load argument count into r13
lpst:
conout QWORD PTR [r12],lf ; QWORD PTR for array member
add r12, 8 ; add 8 to get next array member
sub r13, 1 ; decrement the argument counter
jnz lpst ; loop back if not zero
conout "arg count = ",str$(acnt),lf,lf ; display arg count
; -----------------------------------
; ***********************************
; free cmd arg processing memory
; ***********************************
CmdEnd ; end here
RestoreRegs
.exit
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end