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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:50:33+00:00 2026-05-27T16:50:33+00:00

I’m currently trying to understand some assembler code well enough to reconstruct the C

  • 0

I’m currently trying to understand some assembler code well enough to reconstruct the C code from it. While I’m nearly done with that, there is one thing about local variables that puzzles me.

Local variables are accessed by using the Base Pointer esp and substract their offsets, e.g. -0xc(%ebp) references a local variable. To interpret that into C code I need to know of which size these variables are (at least if they are arrays). One can do that by calculating the differences to the offsets of other variables. If there are the local variables -0xc(%ebp) and -0x8(%ebp) we know that -0xc(%ebp) is most likely 4 bytes long. But what about -0x8(%ebp) if there is no other access to any local variable in the disassebly? Can we suggest that it then must have a size of 8 bytes? I don’t think so…

My problem is this: The compiler seems to set aside more space for local variables than is needed. Let me show you this simple example: An error function, disassembled with gdb.

push   %ebp              
mov    %esp,%ebp      
sub    $0x8,%esp               // 0x8 = 8 byte for local variables
mov    0x8(%ebp),%eax          // errormsg is a function argument  
mov    %eax,(%esp)             
call   0x80485cc <perror@plt>  // perror(errormsg)
movl   $0x1,(%esp)                 
call   0x804866c <exit@plt>    // exit(1)

This function obviously does not access any local variables, so we can suspect there are none. But still there are 8 bytes set aside for local variables, aren’t there?

That’s not the only example I’ve seen where there is space allocated for variables that isn’t needed. I guess I overlook something but as long I do so it is impossible for my to find out about the sizes of all the variables which I need to write C code.

Any suggestions?

Thanks in advance!

  • 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-27T16:50:33+00:00Added an answer on May 27, 2026 at 4:50 pm

    The instruction mov %eax,(%esp) here is used in place of a push. So, whereas there aren’t any local variables used, it’s not like the reserved stack space is wasted. Granted, it looks like the function is reserving 8 bytes for local variables when it only needs to reserve 4, but perhaps that’s the convention used by the compiler: always reserve stack in blocks of 8 bytes. It makes a certain amount of sense to keep the stack qword-aligned.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has

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.