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

  • SEARCH
  • Home
  • 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 6725559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:49:21+00:00 2026-05-26T09:49:21+00:00

I’ve been working with C for a short while and very recently started to

  • 0

I’ve been working with C for a short while and very recently started to get into ASM. When I compile a program:

int main(void)
  {
  int a = 0;
  a += 1;
  return 0;
  }

The objdump disassembly has the code, but nops after the ret:

...
08048394 <main>:
 8048394:       55                      push   %ebp
 8048395:       89 e5                   mov    %esp,%ebp
 8048397:       83 ec 10                sub    $0x10,%esp
 804839a:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%ebp)
 80483a1:       83 45 fc 01             addl   $0x1,-0x4(%ebp)
 80483a5:       b8 00 00 00 00          mov    $0x0,%eax
 80483aa:       c9                      leave  
 80483ab:       c3                      ret    
 80483ac:       90                      nop
 80483ad:       90                      nop
 80483ae:       90                      nop
 80483af:       90                      nop
...

From what I learned nops do nothing, and since after ret wouldn’t even be executed.

My question is: why bother? Couldn’t ELF(linux-x86) work with a .text section(+main) of any size?

I’d appreciate any help, just trying to learn.

  • 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-26T09:49:22+00:00Added an answer on May 26, 2026 at 9:49 am

    First of all, gcc doesn’t always do this. The padding is controlled by -falign-functions, which is automatically turned on by -O2 and -O3:

    -falign-functions
    -falign-functions=n

    Align the start of functions to the next power-of-two greater than n, skipping up to n bytes. For instance,
    -falign-functions=32 aligns functions to the next 32-byte boundary, but -falign-functions=24 would align to the next 32-byte boundary only
    if this can be done by skipping 23 bytes or less.

    -fno-align-functions and -falign-functions=1 are equivalent and mean that functions will not be aligned.

    Some assemblers only support this flag when n is a power of two; in
    that case, it is rounded up.

    If n is not specified or is zero, use a machine-dependent default.

    Enabled at levels -O2, -O3.

    There could be multiple reasons for doing this, but the main one on x86 is probably this:

    Most processors fetch instructions in aligned 16-byte or 32-byte blocks. It can be
    advantageous to align critical loop entries and subroutine entries by 16 in order to minimize
    the number of 16-byte boundaries in the code. Alternatively, make sure that there is no 16-byte boundary in the first few instructions after a critical loop entry or subroutine entry.

    (Quoted from “Optimizing subroutines in assembly
    language” by Agner Fog.)

    edit: Here is an example that demonstrates the padding:

    // align.c
    int f(void) { return 0; }
    int g(void) { return 0; }
    

    When compiled using gcc 4.4.5 with default settings, I get:

    align.o:     file format elf64-x86-64
    
    Disassembly of section .text:
    
    0000000000000000 <f>:
       0:   55                      push   %rbp
       1:   48 89 e5                mov    %rsp,%rbp
       4:   b8 00 00 00 00          mov    $0x0,%eax
       9:   c9                      leaveq 
       a:   c3                      retq   
    
    000000000000000b <g>:
       b:   55                      push   %rbp
       c:   48 89 e5                mov    %rsp,%rbp
       f:   b8 00 00 00 00          mov    $0x0,%eax
      14:   c9                      leaveq 
      15:   c3                      retq   
    

    Specifying -falign-functions gives:

    align.o:     file format elf64-x86-64
    
    Disassembly of section .text:
    
    0000000000000000 <f>:
       0:   55                      push   %rbp
       1:   48 89 e5                mov    %rsp,%rbp
       4:   b8 00 00 00 00          mov    $0x0,%eax
       9:   c9                      leaveq 
       a:   c3                      retq   
       b:   eb 03                   jmp    10 <g>
       d:   90                      nop
       e:   90                      nop
       f:   90                      nop
    
    0000000000000010 <g>:
      10:   55                      push   %rbp
      11:   48 89 e5                mov    %rsp,%rbp
      14:   b8 00 00 00 00          mov    $0x0,%eax
      19:   c9                      leaveq 
      1a:   c3                      retq   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what 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.