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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:05:34+00:00 2026-05-13T11:05:34+00:00

im just curious about the following example #include<stdio.h> int test(); int test(){ // int

  • 0

im just curious about the following example

#include<stdio.h>
int test();
int test(){
     //    int a = 5;
     //    int b = a+1;
     return ;
}
int main(){
     printf("%u\n",test());
     return 0;
}

i compiled it with ‘gcc -Wall -o semicolon semicolon.c’ to create an executable
and ‘gcc -Wall -S semicolon.c’ to get the assembler code which is:

    .file   "semicolon.c"
    .text
.globl test
    .type   test, @function
test:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $4, %esp
    leave
    ret
    .size   test, .-test
    .section        .rodata
 .LC0:
    .string "%u\n"
    .text
 .globl main
    .type   main, @function
 main:
    leal    4(%esp), %ecx
    andl    $-16, %esp
    pushl   -4(%ecx)
    pushl   %ebp
    movl    %esp, %ebp
    pushl   %ecx
    subl    $20, %esp
    call    test
    movl    %eax, 4(%esp)
    movl    $.LC0, (%esp)
    call    printf
    movl    $0, %eax
    addl    $20, %esp
    popl    %ecx
    popl    %ebp
    leal    -4(%ecx), %esp
    ret
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.3.3-5ubuntu4) 4.3.3"
    .section        .note.GNU-stack,"",@progbits

since im not such an assembler pro, i only know that printf prints what is in eax
but i dont fully understand what ‘movl %eax, 4(%esp)’ means which i assume fills eax before calling test
but what is the value then? what means 4(%esp) and what does the value of esp mean?

if i uncomment the lines in test() printf prints 6 – which is written in eax ^^

  • 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-13T11:05:35+00:00Added an answer on May 13, 2026 at 11:05 am

    Your assembly language annotated:

    test:
        pushl   %ebp        # Save the frame pointer
        movl    %esp, %ebp  # Get the new frame pointer.
        subl    $4, %esp    # Allocate some local space on the stack.
        leave               # Restore the old frame pointer/stack
        ret
    

    Note that nothing in test touches eax.

    .size   test, .-test
    .section        .rodata
     .LC0:
    .string "%u\n"
    .text
     .globl main
    .type   main, @function
    main:
    leal    4(%esp), %ecx      # Point past the return address.
    andl    $-16, %esp         # Align the stack.
    pushl   -4(%ecx)           # Push the return address.
    pushl   %ebp               # Save the frame pointer
    movl    %esp, %ebp         # Get the new frame pointer.
    pushl   %ecx               # save the old top of stack.
    subl    $20, %esp          # Allocate some local space (for printf parameters and ?).
    call    test               # Call test.
    

    Note that at this point, nothing has modified eax. Whatever came into main is still here.

    movl    %eax, 4(%esp)      # Save eax as a printf argument.
    movl    $.LC0, (%esp)      # Send the format string.
    call    printf             # Duh.
    movl    $0, %eax           # Return zero from main.
    addl    $20, %esp          # Deallocate local space.
    popl    %ecx               # Restore the old top of stack.
    popl    %ebp               # And the old frame pointer.
    leal    -4(%ecx), %esp     # Fix the stack pointer,
    ret
    

    So, what gets printed out is whatever came in to main. As others have pointed out it is undefined: It depends on what the startup code (or the OS) has done to eax previously.

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

Sidebar

Related Questions

Quick question if I may: I am just curious about the following (see below)
I'm just curious about this: When evaluating 1/0 in Java, the following exception occurs:
Just curious about what would be the django way of achieving the following :
I'm just getting curious about the following code : public static class Container<T> {
I was just curious about this: the following code will not compile, because we
I'm just curious about the efficiency of pattern matching in Haskell. What is a
I'm just curious about this. It strikes me that the behavior of a StringBuilder
I'm just curious about this really, does anyone know why they broke convention on
I was just curious about the password mode display of the TextInput control in
This is mostly a theoretical question I'm just very curious about. (I'm not trying

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.