从内存移动到内存在技术上是可能的。
尝试使用MOVS(移动字符串),并设置[E]SI和[E]DI,具体取决于您是否要传输字节、字等。
mov si, t_cur ; Load SI with address of 't_cur'
mov di, t_last ; Load DI with address of 't_last'
movsb ; Move byte from [SI] to [DI]
; Some dummy data
t_cur db 0x9a ; DB tells NASM that we want to declare a byte
t_last db 0x7f ; (See above)
但是请注意,这比执行两次MOV效率低,但它确实在一条指令中执行了副本。
以下是MOVS的使用方法及其工作原理:
https ://www.felixcloutier.com/x86/movs:movsb:movsw:movsd:movsq
指令MOVS几乎从不单独使用,并且大部分与REP前缀一起使用。
现代 CPU 具有相当高效的实现rep movs
,接近使用 AVX 矢量加载/存储指令的循环速度。
; - Assuming that 't_src' and 't_dst' are valid pointers
mov esi, t_src ; Load ESI with the address of 't_src'
mov edi, t_dst ; Load EDI with the address of 't_dst'
mov ecx, 48 ; Load [ER]CX with the count (let's say 48 dwords = blocks)
rep movsd ; Repeat copying until ECX == 0
从逻辑上讲,复制发生在 48 个 4 字节 dword 块的副本中,但真正现代的 CPU(快速字符串/ERMSB)将使用 16 或 32字节块来提高效率。
本手册解释了应如何使用
REP及其工作原理: https ://www.felixcloutier.com/x86/rep:repe:repz:repne:repnz