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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:00:31+00:00 2026-06-02T05:00:31+00:00

Why do we have commands like push and pop? From what I understand pop

  • 0

Why do we have commands like push and pop?

From what I understand pop and push are basically the same as doing a (mov then add) and (sub then mov) on esp respectively.


For example wouldn’t:

pushl %eax

be equivalent to:

subl $4, %esp
movl %eax, (%esp-4)

please correct me if stack access is not (%esp-4), I’m still learning assembly


The only true benefit I can see is if doing both operation simultaneously offers some advantage; however I don’t see how it could.

  • 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-02T05:00:34+00:00Added an answer on June 2, 2026 at 5:00 am

    But then, there’s no reason for a CALL instruction, either. After all, you can simulate a call with:

    sub esp,4
    mov [esp-4], offset return_address
    jmp myproc
    

    And there’s no need for a RET instruction, either, because you can simulate it with:

    mov eax,[esp]
    add esp,4
    jmp [eax]
    

    If you look hard enough, you’ll find lots of instructions that can be simulated by combining other instructions. What’s the point?

    The answer to these types of questions is rooted in the long history of the x86 processor family, and in processors that came before it. The designers studied how programmers use processors and created an instruction set that was efficient in terms of execution speed and memory use.

    In the late ’70s, 64 kilobytes was a lot of RAM, and RAM was much slower. Every instruction byte was precious, and there was a huge amount of overhead just fetching an instruction from memory. It was not uncommon for instruction fetch to take longer than execution. So there was a huge performance gain to be had by encoding things in as few instruction bytes as possible.

    RAM is still incredibly slow when compared to CPU clock speeds, so there’s still a gain to be had by encoding in as few instruction bytes as possible. It’s true that the large CPU caches we have help a great deal, as does branch prediction and prefetch logic, but every byte transferred from RAM to the CPU cache is still expensive. It pays to be frugal with instruction encodings.

    About calling procedures:

    The standard way of calling procedures in assembly language is to push the parameters and then call the procedure. For example, this passes two dword values:

    push eax
    push ebx
    call proc    ; pushes the return address and jumps to proc
    ...
    
    proc:
      ; at this point, [esp] contains the return address
    

    The ret instruction pops the return address into the instruction pointer.

    Somebody has to clean up the stack, of course. The caller can clean up the stack by incrementing the stack pointer. Or the called procedure can clean up the stack by using ret 8, which will pop the return address and increment the stack pointer.

    See http://www.delorie.com/djgpp/doc/ug/asm/calling.html for more info on calling conventions.

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

Sidebar

Related Questions

I would like to clone a project from a Git server and then perform
I have a command-line process I would like to automate and capture in C#.
I have some command-line ruby scripts for things like pre-processing text files before uploading
I have a complex command that I'd like to make a shell/bash script of.
I have a single windows shell command I'd like to run (via EXEC master..xp_cmdshell)
Let's say I have an object who's class definition looks like: class Command: foo
I have something like this in my project: add_custom_command(OUTPUT somefile) add_custom_target(tgt ALL DEPENDS somefile)
The (command line) interface I have in mind is like so: watching FILE+ do
I have a Makefile that looks something like this: sometarget: command_one # calls fork()
I have a template class defined like so: template <class T> class Command {

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.