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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:58:27+00:00 2026-06-10T23:58:27+00:00

I have a question about assembly code generated by GCC (-S option). Since, I

  • 0

I have a question about assembly code generated by GCC (-S option).
Since, I am new to assembly language and know very little about it, the question will be very primitive. Still, I hope somebody will answer:

Suppose, I have this C code:

main(){

    int x = 15; 

    int y = 6;

    int z = x - y;


    return 0;
}

If we look at the assembly code (especially the part corresponding to int z = x – y ), we see:

main:

...
subl    $16, %esp
movl    $15, -4(%ebp)
movl    $6, -8(%ebp)
movl    -8(%ebp), %eax
movl    -4(%ebp), %edx
movl    %edx, %ecx
subl    %eax, %ecx
movl    %ecx, %eax
movl    %eax, -12(%ebp)
...

Why doesn’t GCC generate something like this, which is less copying things around.

main:

...
movl    $15, -4(%ebp)
movl    $6, -8(%ebp)
movl    -8(%ebp), %edx          
movl    -4(%ebp), %eax          
subl    %edx, %eax              
movl    %eax, -12(%ebp)
...

P.S.

Linux zion-5 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

  • 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-10T23:58:28+00:00Added an answer on June 10, 2026 at 11:58 pm

    First, as Mysticial commented, you should turn on some optimizations. Try passing -O2 (or -O3, or just -O1) to gcc. If you want to understand more the generated assembly code, also pass -fverbose-asm. If you want to understand why the code is generated (or not generated), learn GCC internals (perhaps pass also -fdump-tree-all and -fdump-rtl-all which produces a big lot of internal dump files).

    Some slides on MELT (MELT is a domain specific language to extend GCC) might help and give other references.

    You might be surprised by the amount of optimizations GCC can give you, when asked to. By default GCC does not optimize. There are some optimizations which you should explicitly ask for (not even done at -O3).

    Recent versions of GCC probably optimize more than older ones. Current GCC version in 2021 is GCC 11.

    PS. I don’t work anymore on MELT (abandoned it in 2017). in 2021, see also Bismon, RefPerSys, Frama-C.

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

Sidebar

Related Questions

I have some question about assembly, is it possible to convert ASCII code of
I have a basic question about assembly. Why do we bother doing arithmetic operations
I have a question about how GC works in Java. Consider the following code:
I have this question about c# language's dynamic binding behavior. Consider the following object
I have a simple question that I think someone will answer very fast, but
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,

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.