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

Command-line arguments?

 
0
  #1
Oct 14th, 2009
Would anyone know how to get command-line arguments in NASM16? I am on a Windows XP. I have tried a great deal of things and spent much time searching for an answer to this.

What I ment by command line arguments, something simple like this would be enough.

Filename: Hello1
Params: one two three

So when you type "hello1 one two three", it would see that you typed "one two three", and say something along the lines of

Param 1: One
Param 2: Two
Param 3: Three

I am really against using C libraries (I prefer to do everything purely in assembly).. So if it is possible to do it without C, I would really appreciate your time to answer.

Someone may ask "Why would you want to do this? Just use a higher level language.".. My short answer would be that I enjoy using assembly over a high level language, because of its complexity.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 421
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 48
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Pro in Training
 
0
  #2
Oct 14th, 2009
Not sure what NASM16 is? Is this 16 bit programming?
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
  #3
Oct 14th, 2009
I would assume so. It came with the book "Assembly language step-by-step". I have had it for a while and it works fine. (After looking around, MASM32 is 32 bit, so I think Nasm16 would be 16 bit).

And not sure if this means it's 16 bit, but I normally put [bits 16] at the top of my code.

Is it possible to get a command-line argument with C? I do not like the use C libraries because to me it does not feel like real assembly. To me, real assembly is 100% machine instructions.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 421
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 48
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Pro in Training
 
0
  #4
Oct 14th, 2009
I know how to do it in 64 bit assembly using Linux's as. You just take the offset of the rsp register.i.e

16(%rsp) will get the first command-line argument

In 32 bit Linux's as

8(%esp) to get the first command-line argument

...For 16 bit...I don't think Linux supports 16 bit exe's so I never had the opportunity to try but if it did it would probably be an offset of the ss:sp registers...Hope this helps
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
  #5
Oct 14th, 2009
Thanks. I would not know how to test this on windows as I have never used Linux, but I appreciate your time to reply.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 421
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 48
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Pro in Training
 
0
  #6
Oct 14th, 2009
Originally Posted by Goalatio View Post
Thanks. I would not know how to test this on windows as I have never used Linux, but I appreciate your time to reply.
Windows will pass the command line arguments via the stack so you'll get then by taking an offset of the stack pointer. In 16 bit programming I believe that is accomplished with ss:sp

where ss is the segment register and sp is the stack pointer together they will give you the base of the stack
Last edited by gerard4143; Oct 14th, 2009 at 6:21 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
  #7
Oct 14th, 2009
How would I go about doing that? The most i've ever done with assembly was a "Press any key to view its hexidecimal\binary value". I think I may have heard of ss:sp before, but I have no clue how to do anything with them. I understand if you don't have the time to make a code to show me.
It's passion that drives me.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 421
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 48
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Pro in Training
 
0
  #8
Oct 14th, 2009
Try this link. It discusses 16 bit programming with nasm

http://developer.apple.com/mac/libra.../nasmdoc7.html
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
  #9
Oct 14th, 2009
That did help a bit. But I still cannot get it to work.. I did, however, make a code as proof that I tried. It is supposed to check if the first argument is the "a" key, then display "It works" if it works.
Here is the code.

  1. [org 0100h]
  2. [section .text]
  3.  
  4.  
  5.  
  6. start:
  7. call arg
  8. cmp bx,61h ;Check if first arg is "a"
  9. je works ;Say it worked if it did
  10. jne notwork ;Say it didnt work if it didnt
  11.  
  12.  
  13. arg:
  14. push bp
  15. mov bp,sp
  16. sub sp,0x40
  17. mov bx,[bp+4]
  18. mov sp,bp
  19. pop bp
  20. ret
  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: Jan 2008
Posts: 421
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 48
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Pro in Training
 
0
  #10
Oct 14th, 2009
Did you try Googling "Windows XP 16 bit programs"

http://pcs.suite101.com/article.cfm/...atability_mode
Last edited by gerard4143; Oct 14th, 2009 at 8:30 pm.
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