flat assembler
Message board for the users of flat assembler.
Index
> DOS > Getting the Command line arguments? |
Author |
|
Dryobates 09 Jan 2004, 10:04
mov dx,[cl] <- is it some new addresing mode? You should use bx or some index register.
It looks like you are writing com file (there's no MZ format specifer). So you should write it eg. this way: Code: org 100h ;it looks some weird for me if this is in dec use16 mov bx, 82h ;load address of first character in Argument in bx, we leave first character - space putchar: mov dx, [bx] ;bx, si or di, to be fair we should use: mov dl, byte [bx], but putc uses only dl part of dx, so we can simply move whole word. mov ah, 2 ; call putc int 21h ; putc inc bx ; loop through command line cmp bx, 90h ; until 15 characters from argument are read jna putchar ret ; in com files you can just use ret to leave program |
|||
09 Jan 2004, 10:04 |
|
WhiteDwarf 09 Jan 2004, 23:49
This works but doesn't. Lol
It works because it gets the command line But it doesnt because: look at example outputs of my program "console" C:\fasmw150>console Output: " SET BLASTER =" C:\fasmw150>console and Output:"ET BLASTER =" C:\fasmw150>console arguments Output:"STER=ents" C:\fasmw150>console longargumentlist Output:"longargumentlis" I only want to load the arguments if they've been entered. And I don't want to read the other characters in the PSP besides the arguments......thanks alot |
|||
09 Jan 2004, 23:49 |
|
WhiteDwarf 10 Jan 2004, 00:13
Ok i found something that should greatly help
Code: org 100h use16 mov ax,5053h int 05h mov [commandline],ax mov dx,commandline mov ah,2 int 21h ret commandline: I'm sure this is very easy to fix, but i'm finding a great lack of Fasm documentation....But anyways, i heard that argc is stored in CX, and the argv pointer is returned in AX |
|||
10 Jan 2004, 00:13 |
|
Dryobates 10 Jan 2004, 13:52
WhiteDwarf wrote: I only want to load the arguments if they've been entered. And I don't want to read the other characters in the PSP besides the arguments......thanks alot Oh, that's a problem At 80h there is stored length of arguments. Just check how much you need to read and read 15 characters or less. Code: org 100h ;it looks some weird for me if this is in dec use16 mov bx, 80h ;load address of counter mov cl, [bx] ;load counter test cl, cl jz bye dec cl ;we don't want print EOL, do we? inc bx ;move to first character inc bx ;skip 1 space. I would rather use scasb to skip all spaces putchar: mov dl, [bx] ;bx, si or di, to be fair we should use: mov dl, byte [bx], but putc uses only dl part of dx, so we can simply move whole word. mov ah, 2 ; call putc int 21h ; putc inc bx ; loop through command line dec cl jz bye ;if there is no more characters we can leave program cmp bx, 90h ; until 15 characters from argument are read jna putchar bye: ret ; in com files you can just use ret to leave program And that, what you find (int 5h) as I know, gets parameters but according to RBIL, parameters of "PSPS is shareware PostScript PrintScreen utility by A.N.D. Technologies" |
|||
10 Jan 2004, 13:52 |
|
WhiteDwarf 10 Jan 2004, 20:18
So if i wanted to load the parameters into a variable. Is my way the best? or are there interrupts that could ...get the string for me and i'd just have to move it into a variable.
|
|||
10 Jan 2004, 20:18 |
|
Dryobates 11 Jan 2004, 10:15
WhiteDwarf wrote: So if i wanted to load the parameters into a variable. Is my way the best? or are there interrupts that could ...get the string for me and i'd just have to move it into a variable. I think I didn't understand. Do you want load whole command line string into variable or do you want to split your command line by space and then those parts move to variables? If you want to move (or display this string) that's what I modiffied above is what you can use (but it's not optimal). If you want split into variables, you need do it yourself. I don't know any function interrupt that could do this by you, and... I think it's good. I not always want to have splitted this string. Thats asm. You have got more control |
|||
11 Jan 2004, 10:15 |
|
WhiteDwarf 12 Jan 2004, 03:26
here's my own attempt at it *borrowing some of your techniques* just does a size check instead of loading first X characters from argument line.
Code: org 100h ;took your advice lol use16 org 100h use16 mov bx,80h mov cl,[bx] test cl,cl jz NoArguments add cx,bx inc bx Again: inc bx cmp bx,cx ja NoArguments mov dl,[bx] mov ah,2 int 21h jmp Again NoArguments: ret And here's an argc function i wrote Code: org 100h use16 mov ax,0 mov bx,80h mov cl,[bx] test cl,cl jz NoArguments dec cl add cx,bx Again: inc bx cmp bx,cx ja NoArguments mov dl,[bx] cmp dl,20h jne Again inc ax jmp Again NoArguments: mov dx,ax add dl,'0' mov ah,2 int 21h ret Tell me what you think. |
|||
12 Jan 2004, 03:26 |
|
Dryobates 13 Jan 2004, 09:36
Nice, but if there is more then one space between parameters then it'll count wrong. A little shorter version without this error:
Code: org 100h use16 mov dx, '0' mov di, 80h mov cl, [di] xor ch, ch inc di inc cx mov al, 20h Again: repe scasb ;skip leading spaces test cx, cx ;test if there is no more arguments je NoArguments inc dx ;inc arguments count repne scasb ;skip parameter jmp Again NoArguments: mov ah,2 int 21h ret Ofcourse if there is more then 9 parameters it will show some characters other then digit I think you should read a little about instructions, which deals with strings (lods, movs, scasb, cmps etc.). It'll help you write simpler routines. |
|||
13 Jan 2004, 09:36 |
|
WhiteDwarf 14 Jan 2004, 03:20
Aight thanks, i'll have to look into that. Would you mind if i uploaded your code to my site for demonstrative purposes?
|
|||
14 Jan 2004, 03:20 |
|
Dryobates 14 Jan 2004, 15:46
Do with it whatever you want
|
|||
14 Jan 2004, 15:46 |
|
Bitdog 18 Jan 2004, 16:38
Code: org 100h use16 MOV SI,80h ;ARGC cmnd line count byte adr in PSP LODSW ;inc SI=82h now = ARGV OR AL,AL ;check for AL=0 JZ NOinput MOV CL,AL XOR CH,CH JCXZ NOinput ;another type of check if AL=0 DEC CX ;off by 1 ? ARGC counts space at [81h] JZ NOinput CMP AL,5 ;decide if your program requires a minimum of input JB NOinput ;print error message AH=9 DS:DX=msg adr INT 21h stuff MOV DI,BUFFER ;store WORD offset adr of each input at ES:DI MOV AX,SI ; 82h = first adr STOSW ; save adr PARCE: LODSB ;get byte into AL from DS:SI & INC SI CMP AL,13 ;CR=13 end of command line JZ EOLcmnd ;redundant with CX=LOOP count CMP AL,'a' JB NOlowr CMP AL,'z' JA NOlowr OR AL,11011111b ;clear bit-5 = alph to UPPER case NOlowr: CMP AL,32 ;space=32 JNZ NOspac MOV AX,SI STOSW ; put address of next input into BUFFER XOR AL,AL ;AL=0=NUL=ASCIIZ file name, alter the command line in the PSP = ok. NOspac: MOV BYTE [SI-1],AL ;write un/altered byte to were is was in PSP LOOP PARCE ;use CX to loop (choose one) JMP BYTE PARCE ;use CR check to end loop, JMP SHORT PARCE ;program code here ;exit code here BUFFER: ;end of .COM code label, starts 60k+? usable buffer. ;untested code above, duplicates a bunch of junk, :shows different ways to deal with input, ;needs to be debuged & converted to your needs. ;here's something I just discovered: BUFFER: ;end of .COM code label BUFsize = 0xFF00-$ ;BUFsize is the size of the usable buffer between the codes end & the stack = sizeof 0xFF ;a .COM loads to 0x10000 bytes, the .COM code is small, it needs a stack space reserved ;from 0xFFFE on up to the code & 100h is enough. ;BUFsize is usefull for loading files into your buffer. I hope that helps some how. Bitdog |
|||
18 Jan 2004, 16:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.