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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:41:31+00:00 2026-06-07T05:41:31+00:00

Could someone please help me understand what the push_test() and pop_test() methods are attempting

  • 0

Could someone please help me understand what the push_test() and pop_test() methods are attempting to test? These methods are attempting to test something and I can’t figure out what that is.

The following code is written in c:

int push_test() {
    int ret_val;
    /* movl %esp, %eax    ;; save stack pointer
       pushl %esp         ;; push stack pointer onto stack
       popl %edx          ;; pop the stack into %edx
       subl %edx, %eax    ;; subtract the two values
       movl %eax, ret_val ;; set up the return value
    */
    asm("movl %%esp, %%eax; pushl %%esp; popl %%edx; subl %%edx, %%eax; movl %%eax, %0"
          : "=r" (ret_val)
          : /* no input */
          : "%edx", "%eax");
    return ret_val;
 }

int pop_test() {
  int ret_val = 0xffffffff;  /* -1 in decimal */
  /* pushl ret_val       ;; save ret_val on the stack
     movl %esp, %edx     ;; save the stack pointer
     popl %esp           ;; pop stack into the stack pointer
     movl %esp, ret_val  ;; set the popped value as the return value
     movl %edx, %esp     ;; restore original stack pointer
  */
  asm("pushl %1; movl %%esp, %%edx; popl %%esp; movl %%esp, %0; movl %%edx, %%esp"
      : "=r" (ret_val)
      : "r" (ret_val)
      : "%edx");
  return ret_val;
}

int main() {
  printf("push test: %d\n", push_test()); 
  printf("pop test: %d\n", pop_test()); 
}

/* Output:
  push test: 0
  pop test: -1
*/
  • 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-07T05:41:32+00:00Added an answer on June 7, 2026 at 5:41 am

    Your push_test() and pop_test() is saving the stack state, destroying the stack frame,
    and then doing an operation based on values on the stack.

    Let’s go through each instruction of pop_test() and figure out what it does (push_test() is very similar in operation).

    pushl ret_val pushes -1 onto the stack, incrementing the stack pointer (%esp), so right now your stack looks like: {-1}.

    movl %esp, %edx copies your stack pointer into %edx, so %edx contains the memory address of position 1 on the stack, so right now your stack looks like : {-1}, %esp: stack[1], %edx : stack[1]

    popl %esp pops -1 and stores it into %esp, so the stack looks like: {}, %esp: -1, %edx:stack[1]

    movl %esp, ret_val takes the value of %esp, currently -1, and moves it into ret_val, so ret_val becomes -1.

    finally movl %edx, %esp puts the value of %edx back in %esp and returns -1.


    This method always returns -1. The idea is to push a value onto the stack, pop it back off, and see if the value stays the same. It also destroys and reforms the stack (by temporarily destroying and then restoring %esp). I would guess this is probably some learning assembly kind of deal and not an actual testing method.

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

Sidebar

Related Questions

Please could someone help me understand why the div.fl element shown in Developer Tools
Could someone please help explain why I can't get this to work? I properly
I'm quite new to Spring Framework. Could someone please help me understand the spring
Could someone please help me to understand why the following block of code keeps
Could someone here please help me understand how to determine when floating point limitations
Could someone please help me understand what the link tags are used for within
SQL Server Mgmt Studio 2005: could someone please help me understand how to view
Could someone please help me to understand what Unity is and how it's simplifying
Could someone please help me to understand what the 'send()' method listed below is
Could someone please help me understand that why am I getting this error at

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.