Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:53:25+00:00 2026-06-12T04:53:25+00:00

i have written a c program for printing the arguments #include<stdio.h> void main( int

  • 0

i have written a c program for printing the arguments

#include<stdio.h>
void main( int argc, char *argv[])
{
int i=0;
for(i=0;i<argc;i++)
printf("argument %d=%s\n",i,argv[i]);
}

The assembly dump for the above program using gdb i got is.

Dump of assembler code for function main:
0x00000000004004f4 <+0>:    push   %rbp
0x00000000004004f5 <+1>:    mov    %rsp,%rbp
0x00000000004004f8 <+4>:    sub    $0x20,%rsp
0x00000000004004fc <+8>:    mov    %edi,-0x14(%rbp)
0x00000000004004ff <+11>:   mov    %rsi,-0x20(%rbp)
0x0000000000400503 <+15>:   movl   $0x0,-0x4(%rbp)
0x000000000040050a <+22>:   movl   $0x0,-0x4(%rbp)
0x0000000000400511 <+29>:   jmp    0x40053e <main+74>
0x0000000000400513 <+31>:   mov    -0x4(%rbp),%eax
0x0000000000400516 <+34>:   cltq   
0x0000000000400518 <+36>:   shl    $0x3,%rax
0x000000000040051c <+40>:   add    -0x20(%rbp),%rax
0x0000000000400520 <+44>:   mov    (%rax),%rdx
0x0000000000400523 <+47>:   mov    $0x40063c,%eax
0x0000000000400528 <+52>:   mov    -0x4(%rbp),%ecx
0x000000000040052b <+55>:   mov    %ecx,%esi
0x000000000040052d <+57>:   mov    %rax,%rdi
0x0000000000400530 <+60>:   mov    $0x0,%eax
0x0000000000400535 <+65>:   callq  0x4003f0 <printf@plt>
0x000000000040053a <+70>:   addl   $0x1,-0x4(%rbp)
0x000000000040053e <+74>:   mov    -0x4(%rbp),%eax
0x0000000000400541 <+77>:   cmp    -0x14(%rbp),%eax
0x0000000000400544 <+80>:   jl     0x400513 <main+31>
0x0000000000400546 <+82>:   leaveq 
0x0000000000400547 <+83>:   retq   
End of assembler dump.

Now what i want is ” The memory locations (addresses) at which the argument is passing.
for eg if i run the program as ” arg 1″
it prints the arguments.
Now I want to know on which instruction it is extracting this argument ,or which register holds the arguments (also take the case if i pass more than 1 argument.. (will this tell me the memory address on which it resides?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:53:26+00:00Added an answer on June 12, 2026 at 4:53 am

    I want to know on which instruction it is extracting this argument ,or
    which register holds the arguments

    This sort of question is best answered by obtaining an assembly language reference manual for the target machine and studying it. However, your specific questions are easily answered by examination without being very familiar with the specifics of the assembly language:

    0x0000000000400503 <+15>:   movl   $0x0,-0x4(%rbp)
    0x000000000040050a <+22>:   movl   $0x0,-0x4(%rbp)
    

    This is the code generated for the redundant i = 0 statements.

    0x0000000000400513 <+31>:   mov    -0x4(%rbp),%eax
    

    The value of i is now in the %eax register.

    0x0000000000400518 <+36>:   shl    $0x3,%rax
    0x000000000040051c <+40>:   add    -0x20(%rbp),%rax
    

    This calculates the address of argv[i] and puts it in the %rax register.

    0x0000000000400520 <+44>:   mov    (%rax),%rdx
    

    This loads the value of argv[i] into the %rdx register. Code following calls printf with i and argv[i] as arguments.

    Now what i want is ” The memory locations (addresses) at which the
    argument is passing.

    You can no more determine that by looking at the asm than you can determine the value of argc by looking at the asm … these are values that vary and are only determined when actually running the program. If you want to determine the address at runtime, you could use

    printf("address of argv = %p\n", (void*)argv);
    

    If that’s what you want, then dumping asm and learning what it means is unnecessary and not relevant to your goal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have program written in C. It takes 2 arguments username/password and try to
I have written this program that has a main function, inside which, I am
I have written a program that invokes a system command from inside: #include <stdlib.h>
I have written php program and uploaded on server. I want run this program
I have written a program in VB6. When I compile it and send it
I have written a program that uses qhttp to get a webpage. This works
I have written my program in python. It is written across seven files and
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I have written a java program generates lots of files (say txt files) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.