Example 2.4 x86 instruction complex

  x86 instruction set as a representative of the complex, naturally there will be a lot of fairly complex instructions. In this section we will see some of which are representative examples.
  Operation command string is a data string to operate a memory in each element. Element may be called a byte or word. This string can be very long, it is possible to reach 64KB, x86 provides five different operation command string, and there are three kinds of repeating prefix, it can be used with the string operation instruction. This table shows the five kinds of on the string operation instruction and three repeat prefix. Let's choose a group presentation. This instruction format is very simple, no operands, its function is transferred to the memory cell designated in a byte location in the memory to another specified location. It is often mating with the REP prefix repeated, the architecture of the x86 there are many prefix, the prefix meaning when the value of the CX register is not equal to zero, the string is repeatedly performed on the operation instruction. So it is strange that this directive does not have any operands. In fact, we should note that there are a lot of them x86 instruction operand is not so, but that does not mean that they are simpler than those of instruction operands. Because they do not write operands, not because there is no operands, probably because the number of operations too much, it can not be written in the instructions, so they actually have some implicit operands. For this transfer instruction sequence, the data sequence to be transmitted is referred to as its source string. Default address of the source string in DS: SI location register points of the set. The object to be transmitted, we called the destination address of the string, the default on ES: DI points to the location of the set of registers, the length of the string to be transmitted is placed among the CX register. We can see that, although there is no written operands, but it actually has five registers as its operands. It has not only implied operands, there are some implicit operations, in addition to String transmitted addition, after completion of this operation, these operations will be done automatically on the hardware: the first modification SI and DI registers, to point to the next string element. And then determine whether to use a repeat prefix, and if so, then the contents of the CX register is decremented by 1, to be noted that these hardware operations are done automatically, the programmer need not specified in software. 
  We look at an example. Suppose we want to conduct a memory in the data string transfer. Source string of the address 12040 position in the beginning, a total of three bytes, we want to transfer to the local 12060 to start. That is the program we write this, the assumption has been previously configured the data segment register DS 1000, the first two instructions of this program is actually transfer the contents of the data segment to register an additional segment register them. But can not be directly transferred between the segment register, so borrowed AX, and the offset address stored in the source string SI among registers, into the object string offset address register in which DI, so that the set of registers DS and SI points to the source string. And the set of registers ES and DI points to a string object. CLD next instruction, which is the direction of transmission is determined, one will be explained. 3 is then stored in the CX register them, then this is a string transfer instruction. Preceded by a repeat prefix, such a configuration is equivalent to three times of this continuous execution transfer instruction string. After performing the first transmission, the first byte is transferred to the position of the object of the string, after the transfer is complete, the SI and DI are automatically increased, the CX automatically decremented. These operations are done by the CPU. At the same time I would like to explain the so-called transfer this byte is actually being initiated to the 12040 CPU address read, read into the CPU, and then initiates a write operation to the memory 12060 address written to the corresponding byte unit. After the second transfer, SI and DI 1 has been added, and CX is decremented by 1, after the third transfer is complete, continue to add while SI and DI 1, but has been reduced to CX 0, so no longer run. It is further noted that the direction of conveying the string also can be set. If DF = 0, is transmitted from the start address of the source string is low, during the transfer, the SI and DI are modified automatically increment. If DF- = 1, the start address of the source transmitted from the high strings, during transmission, the automatic reduction of the SI and DI modifications. This table shows the modification method on SI and DI. How to modify the DF flag that it? In fact, x86 provides two control instructions of flag operate. STD is to DF flag. CLD is the example we have just in that instruction, the DF is cleared. This makes it possible to determine the direction of the string transfer. Providing such a direction actually is a response to the source string and a string of possible object overlap problem. We simply look at a paraphrase. If the source and destination string string in memory are mutually phase do not overlap, this time on the DF set to 0 or 1, it does not matter. But if your source string and a string object overlap, it must be set to DF 1 sequentially transfer start address from the high to the low address, or in green overlapping portion, it will be covered at the beginning of the transmission, resulting in erroneous results. If the source and destination string that the string is in the form of overlapping, DF must be set to zero. 
Start transferring from a low address, the reason is the same. In addition transfer instruction string, there are other types of string operations. For example, in a data stream, to find specific data, or comparing two data strings are identical. So programmers have a very convenient means, for a chunk of data to operate. Therefore, the string operation command is very powerful command, but because the data string among the number of elements there may be a lot, so the string operation instruction execution time can also be very long, this is the need to pay attention.
  Finally, we from an interesting example to look at the complexity of the x86 instruction. This figure is a generic x86 instruction format. Each cell is a little bit instruction format specific field. Then we can write an instruction to people, this instruction is an addition, but there is a prefix LOCK, and we have just learned that the same REP prefix is instruction. This addition, where a source operand is a 32-bit immediate. Another source operand and a destination operand is a 32-bit memory among the memory cells. The memory cell should default data segment, but here designated as mandatory in the additional segment, the address of the memory cell by the register EAX, ECX register and an immediate value obtained by calculation. To calculate the memory address requires one multiplication, two additions to obtain an offset address, segment base, and then shifting and adding operations, then access the storage unit 32 to obtain the number of bits. With 12,345,678 this immediate value, then access this memory cell, the number of the deposit into, this instruction encoding a total of 15 bytes, can be considered a longest x86 instruction the complexity of the x86 instruction is evident.
  Programmers only given a brief instruction, the computer can complete a very complex task, which is naturally a very good thing. The computer seems to be so designed, but unfortunately the world is not so simple, it was suggested exactly the opposite approach, we say the next section.
 
Reference: Peking University Lu Junlin teacher computer architecture course
Notice: if infringement, please inform me and I will delete, thank you!

Guess you like

Origin www.cnblogs.com/morwing/p/11794921.html