One lesson per day (2/75) frequently used commands (transfer and exchange the address to get the segment stack operation)

Source: Internet
Author: User
First, write a few abbreviations and meanings.
Reg-register
Mem-memory
Lmm-immediate count


1. transfer command mov REG/MEM/lmm

The transfer command is equivalent to the value assignment statement of the advanced language. It transfers the source operand (REG/MEM/lmm) to the previous register and memory address.

2. Transfer fill instruction movsx/movzx REG/MEM/lmm
Based on the same function as the mov statement, the input and output parameters of the input and output parameters are filled with the high positions of the destination operands. The input parameters include movsx and movzx.
(1) symbol filling command: movsx
Fill the high data bit of the destination operand with the symbol bit of the source operand.
For example, if Al = 87 h, after the movsx CX Al command is executed, CX is 0ff87h.
(2) zero fill command: movzx
Fill in the high data bit of the destination operand with 0.
For example, if Al = 87 h, after the movzx CX Al command is executed, CX is 0087 H.

3. Switch command xchg REG/MEM
Xchg refers to the command that exchanges the content between two registers, registers and memory variables,The Data Types of the two operands must be the same..

4. Obtain the valid address command Lea Reg mem

Is to transfer the valid address of a memory variable to the Register

5. segment fetch register command lDs/LES/LFS/LGS/LSS Reg mem
LDS transfers a "low character" of the memory unit to the specified register and transfers the "high character" to the segment register Ds.
Les, LFS, LGS, and LSS send high-text to the corresponding segment registers es, FS, GS, and SS.

6. Stack operation commands
The essence of stack is a piece of memory space. The standard access form of stack is different from the general memory access form (access using the memory address), but through the inbound stack (pressure stack) access to the stack (elastic stack) command, and the stack is first-in-first-out. (You can also use the memory address to access stack content.But this is a special method). The following are Stack operation commands.
(1) stack pushing commands: Push, pusha, pushad
-Push REG/MEM: pushes the values in registers and memory units to the stack.
-Pusha: push ax, CX, dx, BX, SP, BP, Si, Di and so on to the stack in sequence.
-Pushad: pushes eax, ECx, EDX, EBX, ESP, EBP, ESI, and EDI to the stack in sequence.
(2) stack play command: Pop, Popa, popad
-Pop REG/MEM: the first value of the stack is displayed to the specified register and memory unit.
-Popa: rounds the stack values to registers such as Di, Si, BP, SP, BX, dx, CX, and ax.
-Popad: records the values in the stack to registers such as EDI, ESI, EBP, ESP, EBX, EDX, ECx, and eax in sequence.

Stack pressure and elastic stack supplement:
ESP/SP registers always point to the beginning of the stack, so in Push, SP = SP-2 or 4, * sp = operand (C syntax, that is, SP register first move two and four digits forward, then write the value to the memory area). When an item POPs, the operand is * sp, SP = SP + 2 or 4.
SP and ax registers are used in 16-bit operating systems. ESP and eax registers are used in 32-bit operating systems. RSP registers can be used in 64-bit operating systems.


Compilation generated by the VC ++ CompilerCodeWhen using the stack, it is not to push and pop according to the standard practice, but to push multiple projects, use esp as the base address, and shift the four digits backward to find the second item, the stack is cleared once after the access is completed, so that the stack is omitted multiple times.

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.