943,985 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 1910
  • Assembly RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 14th, 2009
0
Re: Command-line arguments?
I just did, and still could not find anything on passing command-line arguments.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 14th, 2009
0
Re: Command-line arguments?
I would try experimenting with this line

Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,196 posts
since Jan 2008
Oct 14th, 2009
0
Re: Command-line arguments?
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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 14th, 2009
0
Re: Command-line arguments?
Click to Expand / Collapse  Quote originally posted by Goalatio ...
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
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,196 posts
since Jan 2008
Oct 14th, 2009
0
Re: Command-line arguments?
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).

Assembly Syntax (Toggle Plain Text)
  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, "$"
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 14th, 2009
0
Re: Command-line arguments?
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:
Assembly Syntax (Toggle Plain Text)
  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!
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 14th, 2009
0
Re: Command-line arguments?
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:

Assembly Syntax (Toggle Plain Text)
  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]
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 15th, 2009
0
Re: Command-line arguments?
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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009
Oct 15th, 2009
1
Re: Command-line arguments?
To print out your commandline arguments with
function 9, simply add a '$' to the end of the actual command tail.
example:
Assembly Syntax (Toggle Plain Text)
  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:

Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Oct 16th, 2009
0
Re: Command-line arguments?
Thanks.. This pretty much solved what I was looking for.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Goalatio is offline Offline
72 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: floating point syscall
Next Thread in Assembly Forum Timeline: Big Issue with Assembly Startup





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC