有多少种方法可以将寄存器设置为零? [英] How many ways to set a register to zero?

查看:74
本文介绍了有多少种方法可以将寄存器设置为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇在 x86 程序集中有多少种方法可以将寄存器设置为零.使用一条指令.有人告诉我,他设法找到了至少 10 种方法.

I'm curious how many ways are there to set a register to zero in x86 assembly. Using one instruction. Someone told me that he managed to find at least 10 ways to do it.

我能想到的有:

xor ax,ax
mov ax, 0
and ax, 0

推荐答案

IA32 下如何将 0 in 移动到 ax 有很多可能...

There are a lot of possibility how to mov 0 in to ax under IA32...

    lea eax, [0]
    mov eax, 0FFFF0000h         //All constants form 0..0FFFFh << 16
    shr  ax, 16                 //All constants form 16..31
    shl eax, 16                 //All constants form 16..31

也许是最奇怪的... :)

And perhaps the most strange... :)

@movzx:
    movzx eax, byte ptr[@movzx + 6]   //Because the last byte of this instruction is 0

以及在 32 位模式下(更长的指令将最后的(最重要的)地址字节放在后面)...

and also in 32-bit mode (longer instruction puts the final (most-significant) address byte later)...

  @movzx:
    movzx ax, byte ptr[@movzx + 7]

对于 16 位 x86 cpu 模式,未测试...:

And for 16 bit x86 cpu mode, not tested...:

    lea  ax, [0]

还有……

  @movzx:
    movzx ax, byte ptr cs:[@movzx + 7]   //Check if 7 is right offset

cs: 前缀是可选的,以防 ds 段寄存器不等于 cs 段寄存器.

The cs: prefix is optional in case that the ds segment register is not equal to cs segment register.

这篇关于有多少种方法可以将寄存器设置为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆