Wang Shuang "assembly language" the third edition of the Nineth Chapter principle of transfer instruction

Source: Internet
Author: User

Introduction

The 8086CPU transfer instruction is divided into the following categories:
Unconditional transfer instructions (e.g., JMP)
Conditional Transfer Directives
loop instructions (e.g. loop)
Process
Interrupt

9.1 Operator Offset

The operator offset is a symbol that is handled by the compiler in assembly language, and its function is to obtain the offset address of the label.


9.2 JMP Instructions

JMP is unconditionally transferable, can only modify IP, and can also modify CS and IP at the same time.


9.3 JMP instructions for shifting based on displacement

JMP short designator (go to label execution instruction) This format of the JMP directive implements the intra-segment transfer, which modifies the IP range to -128~127, that is, it moves forward with a maximum of 128 bytes and a backward transfer of up to 127 bytes.

When the CPU executes EB (EB is the machine code for JMP short), it does not know the transfer destination address.

  

jmp short s instruction Read and execute:
1. (CS) =0BBDH, (IP) =0006,cs:ip points to EB (the machine code of JMP short s);
2. Read the instruction code EB 03 into the instruction buffer;

4. The CPU refers to the command in the command buffer eb;
5. instruction EB 03 After execution, (IP) =000bh,cs:ip Point to Inc Ax.

Instructions for "jmp near PTR designator":
1.16-bit displacement = The address of the first byte after the address-jmp instruction at the "label";
The 2.near ptr indicates that the displacement here is 16-bit displacement, which is a near-shift in the segment;
The range of 3.16-bit displacement is -32769~32767, which is indicated by complement;
A 4.16-bit displacement is calculated by the compiler at compile time.


9.4 The destination address of the transfer in the instruction of the JMP instruction

In the JMP short directive, the corresponding machine code does not have a destination address for the transfer, but rather a transfer shift relative to the current IP.

The instruction "jmp far PTR designator" implements a transfer between segments, also known as a distant transfer:
1. (CS) = Paragraph address of the segment where the label is located;
2. (IP) = offset address in the segment where the label is located.
3.far PTR indicates that the instruction uses the segment address and offset address of the designator to modify CS and IP.

  


9.5 JMP instructions for transferring addresses in registers

JMP 16-bit register function: IP = (16-bit register).


9.6 Transfer address in-memory JMP instructions

JMP DWORD PTR Memory Unit address (inter-segment transfer) function: from the memory unit address at the beginning of the two words, the high address of the word is the destination of the transfer of the address, the low address is the purpose of the transfer of the destination offset address.


9.7 jcxz directive

The JCXZ instruction is a conditional transfer instruction, and all conditional transfer instructions are short-shifted , including the shifted displacement in the corresponding machine code, not the destination address. The range of modifications to IP is -128~127.

JCXZ designator instruction Operation: when (CX) =0, (IP) = (IP) + 8-bit displacement).

We can see from the function of jcxz that the function of the instruction "JCXZ label" is equivalent to the following: if ((CX) ==0) jmp short label;.


9.8 Loop command


9.9 significance of shifting based on displacement

JMP short label, JMP near PTR label, JCXZ label, Loop label and several other assembly instructions, their IP modification is based on the transfer destination address and transfer the displacement between the starting address. Does not contain the destination address of the transfer, but contains the displacement distance to the destination site. facilitates the floating assembly of the program segment in memory.

  
9.10 Compiler detection of transfer displacement over bounds

According to the displacement of the instructions, their transfer range is limited by the transfer of displacement, if there is a problem in the source program over the transfer range, the compiler will error when compiling.

Reference: "Small Turtle Collection 0 Basic Primer"

The third edition of Assembly language

Wang Shuang "assembly language" the third edition of the Nineth Chapter principle of transfer instruction

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.