WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
 
Forum
Forum Rules Snippets forum rules

In this forum all the registered users may post their snippets of code they whish to share with the WinAsm Studio community following these basic rules:
* Only snippets of code are accepted in the topics of this forum.
* Discussions, suggestions, requests etc. must be posted in the "Discussions" topic.
* Do not post copyrighted material.
Administrators/moderators may edit, move or delete the entries that do not follow the preceding rules.

 

Get Command Line Parameters, a command line parser that extracts the command line parameters written in pure assembler.

akyprian
Quote Post


Administrator
******

Group: Admins
Posts: 2308
Member No.: 1
Joined: 12-May 04


This is a command line parser that extracts the command line parameters. It is written in pure assembler.

CODE
ParseCommandLine Proc Uses EDI ESI lpCommandLine:LPSTR


MOV ESI,lpCommandLine

CMP BYTE PTR [ESI],'"'
JNE @F
;****************************************************
InQuotes:
ADD ESI,1
CMP BYTE PTR [ESI],'"'
JNE InQuotes
JMP Strip
;****************************************************
@@:
ADD ESI,1
CMP BYTE PTR [ESI],0
JE Ex
CMP BYTE PTR [ESI]," "
JNE @B
;Ok, the exe name is behind us
;****************************************************
;Let us strip spaces
Strip:
ADD ESI,1
MOV AL,BYTE PTR [ESI]
CMP AL,0
JE Ex;No arguments follow
CMP AL," "
JE Strip
;****************************************************
;Let's see if the following
;argument starts with quotes
XOR ECX,ECX
CMP BYTE PTR [ESI],'"'
JNE @F �;NO
ADD ESI,1
MOV ECX,TRUE;YES
;****************************************************
;Let's find the end of this argument

@@:
;Store the start of this argument in EDI
MOV EDI,ESI

SUB ESI,1

Arg:
ADD ESI,1
MOV AL,BYTE PTR [ESI]

CMP AL,0
JE ArgFound

CMP ECX,0;Are we looking for a matching quote?
JE @F;No
CMP AL,'"';Yes
JNE Arg;Matching quote NOT found, try next byte
JMP ArgFound


@@:
CMP AL," "
JNE Arg

;ESI points to the end of this argument

;****************************************************

ArgFound:
PUSH EAX;Let's store BYTE PTR [ESI]

MOV BYTE PTR [ESI],0
;*************************************
;OK we have the argument from EDI to ESI
;Do what ever you want to the argument
;*************************************



IsLast:
POP EAX;Lets remind ourselves of BYTE PTR [ESI]
CMP AL,0;Was it a 0 ?
JNE Strip;No, so command line end not reached, continue parsing
;****************************************************

Ex:

RET

ParseCommandLine EndP

Sponsored Links
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topic

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian