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 6901051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:29+00:00 2026-05-27T07:37:29+00:00

When running a program you can pass paramters, e.g. $ myProgram par1 par2 par3

  • 0

When running a program you can pass paramters, e.g.

$ myProgram par1 par2 par3

In C you can access these paramters by looking at argv,

int main (int argc, char *argv[]) 
{
     char* aParameter = argv[1];  // Not sure if this is 100% right but you get the idea...
}

How would this translate in assembly / x86 machine code? How would you access the variables given to you? How would the system give you these variables?

Im very new to assembly, it seams you can only access registers and absolute addresses. I am puzzled how you could access parameters. Does the system preload the parameters into a special register for you?

  • 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-05-27T07:37:29+00:00Added an answer on May 27, 2026 at 7:37 am

    Function calls

    Parameters are usually passed on the stack, which is a part of memory that is pointed to by esp. The operating system is responsible for reserving some memory for the stack and then setting up esp properly before passing control to your program.

    A normal function call could look something like this:

    main:
      push 456
      push 123
      call MyFunction
      add esp, 8
      ret
    
    MyFunction:
       ; [esp+0] will hold the return address
       ; [esp+4] will hold the first parameter (123)
       ; [esp+8] will hold the second parameter (456)
       ;
       ; To return from here, we usually execute a 'ret' instruction,
       ; which is actually equivalent to:
       ;
       ; add esp, 4
       ; jmp [esp-4]
    
       ret
    

    There are different responsibilities split between the calling function and the function that is being called, with regards to how they promise to preserve registers. These rules are referred to as calling conventions.

    The example above uses the cdecl calling convention, which means that parameters are pushed onto the stack in reverse order, and the calling function is responsible for restoring esp back to where it pointed before those parameters were pushed to the stack. That’s what add esp, 8 does.

    Main function

    Typically, you write a main function in assembly and assemble it into an object file. You then pass this object file to a linker to produce an executable.

    The linker is responsible for producing startup code that sets up the stack properly before control is passed to your main function, so that your function can act as if it were called with two arguments (argc/argv). That is, your main function is not the real entry point, but the startup code jumps there after it has set up the argc/argv arguments.

    Startup code

    So how does this “startup code” look? The linker will produce it for us, but it’s always interesting to know how stuff works.

    This is platform specific, but I’ll describe a typical case on Linux. This article, while dated, explains the stack layout on Linux when an i386 program starts. The stack will look like this:

    esp+00h: argc
    esp+04h: argv[0]
    esp+08h: argv[1]
    esp+1Ch: argv[2]
    ...
    

    So the startup code can get the argc/argv values from the stack and then call main(...) with two parameters:

    ; This is very incomplete startup code, but it illustrates the point
    
    mov eax, [esp]        ; eax = argc
    lea edx, [esp+0x04]   ; edx = argv
    
    ; push argv, and argc onto the stack (note the reverse order)
    push edx
    push eax
    call main
    ;
    ; When main returns, use its return value (eax)
    ; to set an exit status
    ;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way my program can determine when it's running on a Remote
In Windows Server 2003, how I can check if my program is running in
How can I check the umask of a program which is currently running? [update:
I am looking for a method to monitor a running program that I have
I am running a program and want to see what its return code is
I have a .NET CF program (running on a Smartphone) and I have written
I now have a running Java program which only lacks of the final step,that
I have a long-running multithreaded program, and I'd like to occasionally like to call
I'm working on a project where a program running on the mobile phone needs
I've got a PHP command line program running. And I want to connect to

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.