Command-line arguments?

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #11
Oct 14th, 2009
I just did, and still could not find anything on passing command-line arguments.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 403
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 47
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Pro in Training
 
0
  #12
Oct 14th, 2009
I would try experimenting with this line

  1. mov bx,[bp+4]

Try values like
mov bx,[bp+8]
mov bx,[bp+12]

Just keep working your way up the stack...

Note the first value on the stack is the number of arguments

Also the command line argument isn't saved on the stack...a pointer to the command line argument is saved on the stack.
Last edited by gerard4143; Oct 14th, 2009 at 9:20 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #13
Oct 14th, 2009
So saying "cmp bx,1" would check if there was one argument passed? I tried taking the stack all the way up to 28, and got the same results. "It did'nt work" as my message. I do really appreciate your help by the way, is there a way for me to +rep you?
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 403
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 47
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Pro in Training
 
0
  #14
Oct 14th, 2009
Originally Posted by Goalatio View Post
So saying "cmp bx,1" would check if there was one argument passed? I tried taking the stack all the way up to 28, and got the same results. "It did'nt work" as my message. I do really appreciate your help by the way, is there a way for me to +rep you?
cmp bx, 1 should work...at least its an easy way to see if your checking values on the stack...If you get a true for cmp bx, 1 try changing it to cmp bx, 3 and pass three arguments and see if it still works..If it does then try dereferencing the value ahead of it to see if its your string...Good luck
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #15
Oct 14th, 2009
Still does not work. I'll paste my newer code below. Would compiling it as a .com file have any effect? Because that's what I am using (.com).

  1. [org 0100h]
  2. [section .text]
  3.  
  4.  
  5.  
  6. start:
  7. call arg
  8. cmp bx,1 ;Check for first arg
  9. je works ;Say it worked if it found one
  10. jne notwork ;Say it didnt work if it didnt find one
  11.  
  12.  
  13. arg:
  14. push bp ;Save BP
  15. mov bp,sp ;Move SP into BP
  16. sub sp,0x40
  17. mov bx,[bp+4] ;First argument
  18. mov sp,bp ;Move bp into SP
  19. pop bp ;Retore BP
  20. ret ;Return
  21.  
  22. works:
  23. mov dx,msg ;Load "works" message into DX
  24. call disp
  25. call exit
  26.  
  27. notwork:
  28. mov dx,msg1
  29. call disp
  30. call exit
  31.  
  32. disp:
  33. mov ah,9 ;Function 9, display string
  34. int 21h ;Call DOS
  35. ret
  36.  
  37. exit:
  38. mov AH,4CH ; Terminate process DOS service
  39. mov AL,0 ; Pass this value back to ERRORLEVEL (0)
  40. int 21H ; Exit
  41.  
  42.  
  43.  
  44.  
  45. [section .data]
  46. msg db "It worked", 13, 10, "$"
  47. msg1 db "It did'nt work", 13, 10, "$"
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 140
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #16
Oct 14th, 2009
16-bit OS dos I need help vortex reign....
Hello, to answer your question NASM16 is a 16-bit (80x86) assembler
for MS-DOS.
To access commandline parameters, they are passed by the
loader (your parent process) into offset 81h in your PSP.
You have your origin set to 100h so I assume you are assembling
a .COM
So try this:
  1. mov cl, [cs:0x80] ; Get Command Tail Length
  2. mov bx, 0x81 ; place offset of command tail in BX.
Oh yeah, the command tail is but a string of bytes terminated
by a Carriage Return (0xd) and is usually preceded by a
space character (0x20) but not always.
Need more examples, no problem!
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #17
Oct 14th, 2009
Hey, thanks.. but, it did not work.. I may have just set it up wrong though. Would you mind showing a working example of how to use it please?

Code:

  1. [org 0100h]
  2. [section .text]
  3.  
  4.  
  5.  
  6. start:
  7. call arg
  8. call disp
  9. call exit
  10.  
  11.  
  12.  
  13. arg:
  14. mov cl, [cs:0x80] ; Get Command Tail Length
  15. mov bx, 0x81 ; place offset of command tail in BX.
  16. ret ;Return
  17.  
  18.  
  19. disp:
  20. mov ah,9 ;Function 9, display string
  21. int 21h ;Call DOS
  22. ret
  23.  
  24. exit:
  25. mov AH,4CH ; Terminate process DOS service
  26. mov AL,0 ; Pass this value back to ERRORLEVEL (0)
  27. int 21H ; Exit
  28.  
  29.  
  30.  
  31.  
  32. [section .data]
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #18
Oct 15th, 2009
Got it working! Thanks! But to make it work, I have to type a $ on the end of the argument. Ex;

ARGS hello1 hello2 hello3$

Or it will not work, I know it's because I am using 'mov ah,9'.. but is there a different way to print a string?
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 140
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
1
  #19
Oct 15th, 2009
To print out your commandline arguments with
function 9, simply add a '$' to the end of the actual command tail.
example:
  1. xor bx, bx
  2. mov bl, [0x80]
  3. mov byte [bx+0x81],'$'
  4. mov bx, 0x81
But remember the command tail length does not include the
carriage return, so it will be overwritten.

Yes there is in fact a few other ways to print
a string, here's one using the BIOS:

  1.  
  2. printstr: ; DS:SI - Null Terminated String
  3. cld
  4. printstr_l:
  5. lodsb
  6. cmp al, 0
  7. jz printstr_e
  8. mov bh, 0
  9. mov ah, 0xe
  10. int 0x10
  11. jmp printstr_l
  12. printstr_e:
  13. ret
Last edited by NotNull; Oct 15th, 2009 at 11:19 pm.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 33
Reputation: Goalatio is an unknown quantity at this point 
Solved Threads: 0
Goalatio Goalatio is offline Offline
Light Poster
 
0
  #20
Oct 16th, 2009
Thanks.. This pretty much solved what I was looking for.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC