zero out top 32 bits of 64-bit register

痞子三分冷 提交于 2019-11-28 01:03:13

问题


Using amd64 assembly, whats the best way to zero out the top 32 bits of a 64-bit register, e.g. zero out the bits of rax that are not covered by eax? It appears that I cannot and the whole register against a 64-bit constant.


回答1:


movl %eax, %eax or mov eax, eax, depending on the assembler in use.

see: Intel® 64 and IA-32 Architectures - Software Developer’s Manual, Volume 1, 3.4.1.1 : General-Purpose Registers in 64-Bit Mode.

32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register.

I should also add, in regards to @HansPassant's comment: 7.3.1.7 :

The MOVSXD instruction operates on 64-bit data. It sign-extends a 32-bit value to 64 bits.



来源:https://stackoverflow.com/questions/21439289/zero-out-top-32-bits-of-64-bit-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!