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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:48:03+00:00 2026-05-27T20:48:03+00:00

I am learning assembly and I have this function that contains some lines I

  • 0

I am learning assembly and I have this function that contains some lines I just don’t understand:

. globl
. text

factR:
 cmpl $0 ,4(% esp )
 jne cont
 movl $1 ,%eax
 ret

cont :
 movl 4(%esp),%eax
 decl %eax
 pushl %eax          // (1)
 call factR          // (2)
 addl $4,%esp        // (3)
 imull 4(%esp),%eax 
 ret

and the C code corresponding to it is:

int factR ( int n ) {
    if ( n != 0 )
        return n;
    else
        return n ∗ factR ( n − 1 );
}

I am not sure about the lines marked with numbers.

  1. pushl %eax: does it mean we put the contents of %eax in
    %esp?

  2. So we call factR(). Will the result of that be in %esp when we come back here to the next instructions?

  3. addl $4,%esp not sure about this one, are we adding 4 to the number stored in %esp or do we add 4 to the pointer to get the next number or something similar?

  • 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-27T20:48:04+00:00Added an answer on May 27, 2026 at 8:48 pm

    It appears that the factR() function follows the C calling convention (cdecl). It is where the caller pushes the arguments to the function call onto the stack and the caller cleans up the stack (undoes the changes to the stack that was made to do the function call) when the function returns.

    The first push (1) is putting the contents of the %eax register as the argument to the following call. Then the actual call to the function is made (2). Then the stack is cleaned (3) by resetting the stack pointer %esp back to the state when it didn’t have the argument pushed back in step 1. It pushed one 32-bit value so it must adjust the pointer by 4-bytes.

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

Sidebar

Related Questions

I'm a beginner learning some assembly, when preserving the ESP register before a function
I'm learning SPARC assembly and I have to create a script that extracts a
I am just learning Blend/Silverlight/VS2010/.net/etc. I have a simple project that resides on a
Just started learning x64 assembly and I have a question about functions, arguments, and
So I have been learning assembly and came to the topic of stack, storing
does anyone have any resources for learning assembly language on x86? I'm trying to
Most people suggest that learning assembly is essential, its important to know the underlying
I've been learning compiler theory and assembly and have managed to create a compiler
I am learning about how compilers represent C++ programs in assembly. I have a
I've created this simple and pointless assembly (Y86) code to see if I understand

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.