更新时间:2023-01-09 15:42:03
假设源数据的第一个字节包含字符串长度,我们可以使用以下内容:
Assuming that the first byte of the source data contains the string length we could have something like:
--------------------------
| 4 | A | B | C | D |
--------------------------
所以MOVE循环会be:
So the MOVE loop would be:
// move the length byte from the source to the destination
MOVE (source,dest,1); // dest[0] now contains 4
for (i=1; i <dest; i++)="" set="" i="1," and="" while="" <="" 4="" do="" the="" following<!--="" newline="" --="">{
MOVE(source[i], dest[i], 1); // move the source byte at offset i to
// the byte at offset i of the destination
} // increment i and repeat while the value of i is less than 4
这将失败,因为循环将因此在复制偏移量4处的字节之前终止:
This will fail since the loop will terminate before copying the byte at offset 4 thus:
Value of i copy byte
1 A
2 B
3 C
4 -> loop terminates since i is not less than byte 0 of dest.
所以for循环需要是
so the for loop needs to be
for (i=1; i <= dest; i++)
大多数指令集使用寄存器实现这一点,寄存器在复制每个字节后自动递增。要复制的编号放在一个特殊的寄存器中,该寄存器会在每次重复复制时倒计时。请参阅英特尔指令集 - REP [ ^ ]。
Most instruction sets implement this using registers that automatically increment after each byte is copied. The number to copy is put in a special register that counts down for each repetition of the copy. See Intel Instruction Set - REP[^].