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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:48:30+00:00 2026-05-19T04:48:30+00:00

I’m trying to learn basic assembly. I wrote a simple program in C to

  • 0

I’m trying to learn basic assembly. I wrote a simple program in C to translate to assembly:

void myFunc(int x, int y) {
    int z;
}

int main() {
    myFunc(20, 10);
    return 0;
}

This is what I thought the correct translation of the function would be:

.text
.globl _start
.type myFunc, @function

myFunc:
    pushl %ebp        #Push old ebp register on to stack
    movl %esp, %ebp   #Move esp into ebp so we can reference vars
    sub $4, %esp      #Subtract 4 bytes from esp to make room for 'z' var
    movl $2, -4(%ebp) #Move value 2 into 'z'
    movl %ebp, %esp   #Restore esp
    popl %ebp         #Set ebp to 0?
    ret               #Restore eip and jump to next instruction

_start:
    pushl $10        #Push 10 onto stack for 'y' var
    pushl $20        #Push 20 onto stack for 'x' var
    call myFunc      #Jump to myFunc (this pushes ret onto stack)
    add $8, %esp     #Restore esp to where it was before

    movl $1, %eax    #Exit syscall
    movl $0, %ebx    #Return 0
    int $0x80        #Interrupt

Just to double check it I ran it in gdb and was confused by the results:

(gdb) disas myFunc
Dump of assembler code for function myFunc:
0x08048374 <myFunc+0>:  push   ebp
0x08048375 <myFunc+1>:  mov    ebp,esp
0x08048377 <myFunc+3>:  sub    esp,0x10
0x0804837a <myFunc+6>:  leave
0x0804837b <myFunc+7>:  ret    
End of assembler dump.

Why at 0x08048377 did gcc subtract 0x10 (16 bytes) from the stack when an integer is 4 bytes in length?

Also, is the leave instruction equivalent to the following?

    movl %ebp, %esp   #Restore esp
    popl %ebp         #Set ebp to 0?

Using:

gcc version 4.3.2 (Debian 4.3.2-1.1)
GNU gdb 6.8-debian
  • 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-19T04:48:31+00:00Added an answer on May 19, 2026 at 4:48 am

    Your GDB is configured to print out Intel instead of AT&T assembly syntax – turn that off before it confuses you more than it already has.

    The stack pointer (%esp) is required to always be aligned to a 16-byte boundary. That’s probably where the sub esp,0x10 is coming from. (It’s unnecessary, but GCC has historically been bad at noticing that stack adjustments are unnecessary.) Also, your function doesn’t do anything interesting, so the body has been optimized out. You should have compiled this code:

    int myFunc(int x, int y)
    {
        return x + y;
    }
    
    int main(void)
    {
        return myFunc(20, 30);
    }
    

    That’ll produce assembly language that’s easier to map back to the original C. GCC would still be allowed to produce

    main:
        movl $50,%eax
        ret
    

    and nothing else, but it probably won’t unless you use -O3 -fwhole-program 😉

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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.