Register usage practices read deep understanding of computer systems

Source: Internet
Author: User

ProgramA register is the only resource shared by all processes. Although only one process is active at a given time, we must ensure that when one process (caller) calls another (called, the called user does not overwrite the value of the Register that a caller will use later. To this end, ia32 adopts a set of unified register usage practices, and all processes must comply with, including the processes in the library.

By convention, registers eax, EDX, and ECx are divided into caller save registers. When P calls Q, Q can overwrite these registers without damaging the data required by P. In addition, registers EBX, ESI, and EDI are divided into callee save registers. This means that Q must save the values of these registers to the stack before overwriting them and restore them before returning, because P (or a higher-level process) these values may be required in future calculations. In addition, according to the conventions described here, the registers EBP and ESP must be saved.


P calculates y before calling Q, but it must ensure that the value of Y is available after Q is returned. There are two ways to do this:

1: it can store the value of Y in its stack frame before calling Q. When q returns, it can retrieve the value of Y from the stack.

2: it can save the value of Y in the caller's storage register. If Q, or any other program called by Q, wants to use this register, it must save the value of this register in the stack frame and restore it before returning. Therefore, when Q is returned to P, the value of Y is stored in the registers by the caller, either because the registers are not changed at all, or because they are saved and restored.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.