"Assembly Language" summarizes the principle of 06--transfer instruction

Source: Internet
Author: User

(i) the foregoing

You can modify the IP, or both CS and IP instructions are collectively referred to as transfer instructions .

The transfer behavior has the following categories:

    1. When you modify IP only, it is called intra-segment transfer, for example: JMP ax.

    2. Simultaneous modification of CS and IPs is called inter-segment transfer, for example: jmp 1000:0.

because the transfer instruction has different scope for IP modification , the transfer is divided into: short transfer and near transfer.

    1. The modified range of the short transfer IP is -128~127.

    2. The modified range of near-transfer IP is -32768~32767.

The 8086CPU transfer instruction is divided into the following categories:

    1. Unconditional transfer instructions (e.g., JMP)

    2. Conditional Transfer Directives

    3. loop instructions (e.g. loop)

    4. Process

    5. Interrupt

Although the preconditions for these transfer instructions may vary, the rationale for the transfer is the same.

(ii) 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. Such as:

Assume CS:CODESG

CODESG segment

Start:mov Ax,offset Start

S:mov Ax,offset S

CODESG ends

End Start

(iii) JMP directives

The JMP directive is an unconditional transfer instruction that can modify only the IP or both CS and IP.

The JMP directive gives you two kinds of information:

    1. The destination address of the transfer.

    2. Transfer distance (inter-segment transfer, intra-segment short transfer, intra-segment near transfer)

(iv) JMP instructions for transfer based on displacement

jmp short label (go to label to execute instruction)

In this format, the JMP instruction implements a short transfer within the segment, which modifies the IP range to -128~127, that is, it can move forward up to 128 bytes, and the backward transfer can be up to 127 bytes. The "short" symbol in the JMP directive, which indicates that the instruction is carried out in a shorter transition. The "designator" in the JMP directive is the designator in the code snippet, indicating the destination to which the instruction is to be transferred, and the CS:IP should point to the instruction at the label at the end of the transfer instruction. Such as:

Assume CS:CODESG

CODESG segment

Start:mov ax,0

JMP Short S

Add ax,1

S:inc Ax

CODESG ends

End Start

JMP near PTR designator (intra-segment transfer)

(iv) The purpose of the transfer of the address in the instruction of the JMP directive

Transfer between segments of JMP far PTR designator

Far PTR indicates that CS and IP are modified with the segment address and offset address of the designator.

(v) Transfer of the JMP instructions in the Register

Instruction format: jmp 16-bit Reg

Function: (IP) = (16-bit REG)

(vi) Transfer address in-memory JMP instructions

    1. JMP Word PTR memory cell address (intra-segment transfer)

      Function: A word is stored at the address of the memory unit, which is the destination offset address of the transfer.

      MOV ax,0123h

      MOV Ds:[0],ax

      JMP word ptr ds:[0]

      After execution, (IP) =0123h

      MOV ax,0123h

      mov [Bx],ax

      JMP word ptr [bx]

      After execution, (IP) =0123h

    2. JMP DWORD ptr memory cell 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.

      MOV ax,0123h

      MOV Ds:[0],ax

      mov word ptr ds:[2],0

      JMP DWORD ptr ds:[0]

      After execution, (CS) =0, (IP) =0123h,cs:ip point to 0000:0123

      MOV ax,0123h

      mov [Bx],ax

      mov word ptr [bx+2],0

      JMP DWORD ptr [BX]

      After execution, (CS) =0, (IP) =0123h,cs:ip point to 0000:0123

(vii) 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.

Instruction format: JCXZ label (if (CX) = 0, transfer to label execution)

Simply put, the function of the JCXZ label is equivalent to:

if ((CX) ==0) jmp short label;

Summary complete!

This article is from the "where No Play" blog, please be sure to keep this source http://liaofan.blog.51cto.com/12295212/1919178

"Assembly Language" summarizes the principle of 06--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.