Displaying all argv in x64 assembly

2013-Jul-25 | Tags: howtolearnprograming

Start64!The Performance Zone is supported by New Relic and AppDynamics. Both are leaders in the APM space with high-profile customers and massive cost reductions for those users. Recently I’ve been doing some x64 assembly hacking, and something I had to Google a bit and collect from a few places is how to go over all command-line arguments (colloquially known as argv from C) and do something with them.

I already discussed how arguments get passed into a program in the past (not the C main, mind you, but rather the real entry point of a program – _start), so what was left is just a small matter of implementation. Here it is, in GNU Assembly (gas) syntax for Linux. This is pure assembly code – it does not use the C standard library or runtime at all. It demonstrates a lot of interesting concepts such as reading command-line arguments, issuing Linux system calls and string processing.