1

How can I get the number of command line parameters in x64 assembly which is ARGC? Im in nasm. Any help would be appreciated. thank you

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
test
  • 11
  • 2
  • 3
    If you aren't using the _C_ startup (you are using `_start` instead of `main`) then ARGC is the value at memory location `[rsp]` . This is documented in the x86-64 System V ABI can be found here: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI . See section _3.4.1 Initial Stack and Register State_ . If your entry point is `main` then ARGC is passed in RDI as described in the same calling convention. It is different for Windows. – Michael Petch Aug 24 '18 at 22:36
  • 3
    The problem is you don't provide us enough information so we have to guess. Saying x64 isn't enough. What OS are you on etc? How are you assembling and linking the code you have. What code have you written that didn't work? Depending on how you assemble/link the method to get the command line arguments and argc differs. – Michael Petch Aug 24 '18 at 23:33
  • 1
    If you are talking about Linux, [x86 Linux assembler get program parameters from \_start](https://stackoverflow.com/q/16721164) has i386 and x86-64, but mostly GAS syntax. [Get argv\[2\] address in assembler x64](https://stackoverflow.com/q/35864291) shows the stack layout in `_start` on Linux, including an example in NASM. Let us know if your question is a duplicate of one of those. – Peter Cordes Aug 25 '18 at 13:18

0 Answers0