I see memcpy
linux内核实模式下的实现:
GLOBAL(memcpy)
pushw %si
pushw %di
movw %ax, %di
movw %dx, %si
pushw %cx
shrw $2, %cx
rep; movsl
popw %cx
andw $3, %cx
rep; movsb
popw %di
popw %si
retl
ENDPROC(memcpy)
我之前理解第一部分rep; movsl
,但是为什么第二部分是在之后rep; movsl
,它已经复制自si
-> di
32 字节。为什么是第二部分,我认为只有一个原因需要再次处理地址所在的结构si
未按 4 字节对齐。
谢谢。
以下是相关代码行,并带有注释来解释它们的作用:
shrw $2, %cx ; length /= sizeof(DWORD)
rep; movsl ; Copy the first length/sizeof(DWORD) DWORDs
popw %cx ; Restore the original length
andw $3, %cx ; length &= 3, i.e. length %= sizeof(DWORD)
rep; movsb ; Copy the remaining length % sizeof(DWORD) bytes (if any)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)