Principle of Transfer Instruction (learning Assembly)

Source: Internet
Author: User

1. IP addresses can be modified, or commands for both CS and IP addresses can be collectively referred to as transfer commands. There are two types of transfer:

(1) only change the IP address to intra-segment transfer, for example, JMP ax

(2) Change CS and IP address to inter-segment transfer, for example, JMP 1000:0

 

2. The offset operator is a pseudo-instruction. Its function is to get the offset address of the label.

 

3. JMP is an unconditional transfer. You can modify only the IP address or the Cs and IP value at the same time. The JMP command must provide two information: (1) the destination address of the transfer. (2) transfer distance (Inter-segment transfer, short transfer and near transfer of intra-segment transfer) 4.jmp short label (to be executed) this command implements short transfer within a segment. The "label" in the JMP Instruction is the label in the code segment, indicating the destination of the instruction to be transferred. The transfer instruction ends. CS: IP points to the instruction at the label. 5. The CPU does not need to specify the destination address of the transfer when executing the JMP command. 6. The machine code corresponding to the "JMP short label" command does not contain the destination address of the transfer, but contains the displacement of the transfer. 7. the "JMP short label" function is as follows: (IP) = (IP) + 8-bit displacement (1) 8-bit shift = address of the label-address of the first byte after the JMP command. (2) Short indicates that the displacement here is 8-bit (3) the range of the 8-bit displacement is-128 ~ 127, which is indicated by a supplementary code. (4) The 8-bit displacement is calculated during compilation. 8. The JMP near PTR label indicates the near transfer within the segment. 9. the "JMP near PTR label" function is as follows: (IP) = (IP) + 16-bit displacement (1) 16-bit shift = address of the label-address of the first byte after the JMP command. (2) The near PTR indicates that the displacement here is 16 bits for near transfer within the segment. (3) The 16-bit displacement range is-32768 ~ 32767, which is indicated by a supplementary code. (4) The 16-bit displacement is calculated by the compiler during compilation. 10. "JMP far PTR label" implements inter-segment transfer, also known as remote transfer. Function: (CS) = segment address of the label; (IP) = offset address of the label segment. Far PTR specifies the CIDR block address and offset address used by the command to modify CS and IP addresses. 11. the transfer address in the memory has the following JMP commands: (1) JMP word PTR memory unit address (intra-segment transfer) 16-bit function: A word is stored at the beginning of the memory unit address, is the offset address of the transfer target. The memory unit address can be given in any format in addressing mode. For example, run the following command: mov ax, 0013 H
MoV DS: [0], ax
JMP word ptr ds: [0] (2) jmp dword ptr memory unit address (Inter-segment transfer) function: put two words at the beginning of the memory unit address, there is a destination segment address at the high address, and an offset address for the destination address at the low address. (CS) = (memory unit address + 2) (IP) = (Memory Unit Address) the memory unit address can be given in any format in addressing mode. For example, run the following command: mov ax, 0123 H
MoV DS: [0], ax
MoV word ptr ds: [2], 0
After jmp dword ptr ds: [0] is executed, (CS) = 0, (IP) = 0123 H, CS: IP points to 12. the jcxz command is conditional transfer, and all conditional transfer commands are short transfer. Command Format: jcxz label (if (CX) = 0, transferred to the label for execution) When CX <> 0, nothing (executed under the Program) 13. loop commands are cyclic commands, and all cyclic commands are short-transferred. Command Format: loop label (CX) = (CS)-1, if (CX) <> 0, transfer to the label for execution) When Cx = 0, do nothing (executed under the Program) 14. the transfer is based on the displacement to facilitate the floating assembly of the program segment in the memory. 15. according to the instruction of displacement transfer, their transfer range is restricted by the transfer displacement. If the transfer range exexceeded problem occurs in the source program, the compiler will report an error during compilation.

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.