-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access command line arguments (argv and argc) in AAarch64/Darwin assembly #22
Comments
Gladly, it is quite easy. This is the entry function:
As per the standard ARM64 ABI, the arguments are in the registers: Let's invoke our executable with
As you can see, x0 contains 2, and x1 points to a position 48 bytes above the current SP (and we can find the value for argc at 40 bytes, too). When we examine the memory pointed to at x1, we see the elements of argv, which are in turn pointers:
The memory pointed to by the doubleword at x1 contains, as expected, the full path to the executable:
And finally, the doubleword at [x1, #8] points to our argument, foo:
With this information, it should be easy to adopt your code! Let me know if it works! |
Thank-you VERY, VERY, VERY much. That worked perfectly and I've modified my program to now grab the command line argument(s) entered and act on them accordingly. Again....thanks tons. Much appreciated!!!!!! |
Please see my adaption of your code in Chapter 4/case.s and feel free to add or edit it |
I'm hoping you can possibly answer this question???
I've been working thru the book and your code changes in order for everything to work on the Machine We Must Not Speak About.
I'm trying to extend one of the Chapter 4 exercises and access the command line argument(s) (argc & argv) within my assembly code. I've searched high and low and just can't find anything that applies (or works).
Could you possibly provide any clues/hints on how to access the command line arguments (argv and argc) within the assembly program.
This very simple program is working fine but if you read the TODO, in the attached code, what I'm trying to do should make sense.
case.txt
Thanks much!
The text was updated successfully, but these errors were encountered: