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

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

问题描述

我很好奇方法有多少种存在于x86汇编寄存器设置为零。用一个指令。有人告诉我说,他设法找到了至少10个办法做到这一点。

我能想到的是:

 异斧,斧
MOV AX,0
和斧头,0


解决方案

有很多的可能性如何以斧头MOV 0下IA32 ...

  LEA EAX,[0]
    MOV EAX,0FFFF0000h //所有常量形成0..0FFFFh<< 16
    SHR EAX,16 //所有常量形成16..31
    SHL EAX,16 //所有常量形成16..31

也许是最奇怪...:)

  @movzx:
    MOVZX EAX,字节PTR [@movzx + 6] //因为该指令的最后一个字节为0

和...

  @movzx:
    MOVZX斧头,字节PTR [@movzx + 7]

编辑:

和16位x86 CPU模式,没有测试...

  LEA AX,[0]

和...

  @movzx:
    MOVZX斧头,字节PTR CS:[@ MOVZX + 7] //检查7右偏移

CS: preFIX是可选的情况下,即在 DS 段寄存器不等于CS段寄存器

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.

The ones I can think of are:

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

解决方案

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 eax, 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

and...

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

Edit:

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

    lea  ax, [0]

and...

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

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

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

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