I want to print out command line arguments out in x86-64 assembly(with AT&T syntax).
This is a followup question to my previous post on how simply to access these arguments. I also wanted to know how to print all command-line arguments to the console.
.globl main
main:
push %rbp # rbp not used, for alignment only
mov %rsp, %rbp
mov %edi, %esi # move argc to second parameter register
lea format_string(%rip), %rdi # the format string is the first parameter
xor %eax, %eax # 0 xmm registers used
call printf@plt
xor %eax, %eax # return 0 to behave nicely
mov 16(%rbp), %rsi # get argv[1] (pointer to first command line argument)
mov (%rsi), %rdi # load the pointer to the first argument into %rdi
lea arg_format(%rip), %rsi # load argument format string
xor %eax, %eax # 0 xmm registers used
call printf@plt
pop %rbp
ret
.section .rodata
format_string: .string "Arguments: %d\n"
arg_format: .string "First Argument: %s\n"