Computing instruction length (assembly)

Source: Internet
Author: User

The instruction length is related to the addressing method. The rule or principle is as follows:

1. commands without operands. The instruction length is 1 byte. For example
ES:
DS:
CBW
Xlat
.

2. the operand only involves the register instruction. The instruction length is 2 bytes. For example
MoV Al, [Si]
MoV ax, [bx + Si]
MoV ds, ax
.

3. the operand refers to the memory address instruction. The instruction length is 3 bytes. For example
MoV Al, [bx + 1]
MoV ax, [bx + Si + 3]
Lea Di, [1234]
MoV [2345], ax
.

4. the operand refers to the immediate number instruction. The instruction length is Register Type + 2.
8-bit register, register type = 1; 16-bit register, register type = 2. For example
MoV Al, 8; Instruction length: 2
MoV ax, 8; Instruction length: 3
.

5. Jump commands are divided into 2, 3, and 5 bytes in three cases.
1. Jump within a segment, command length = (target address-Current Instruction address) + 1
The JMP command occupies 1 byte.
(Target address-current address of the instruction) if it can be expressed in 1 byte, it occupies 1 byte and the overall instruction length is 2 byte. For example:
0113 JMP 0185; 0185 H-0113 H = 72 h, expressed in 1 byte for 72 h
If two bytes are required, the command occupies two bytes and the overall command is three bytes. For example
0113 JMP 0845; 0845 H-0113 H = 732 H, H must be expressed in 2 bytes
2. Inter-segment jump. The instruction length is 5 bytes. For example

JMP 1234: 5678

Reprinted from: http://www.cnblogs.com/onroad/archive/2009/07/13/1522671.html

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.