放入小数字到64位x86寄存器 [英] Loading small numbers into 64 bit x86 registers

查看:144
本文介绍了放入小数字到64位x86寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在64位x86 CPU通常我们载入号-1等来登记:

Under 64 bit x86 CPU normally we load number -1 in to register like:

mov     rdx, -1  //  48BAFFFFFFFFFFFFFFFF

...这个运算code需要10个字节。

... this opcode takes 10 bytes.

另一种方法是:

xor     rdx, rdx //  4831D2        
dec     rdx      //  48FFCA  

...这个运算code只需要6个字节。

... this opcode takes only 6 bytes.

修改

由于延Björnhager说(我已经测试) XOR EDX,EDX 运算code应该清楚整个RDX寄存器:

As Jens Björnhager say (I have tested) xor edx, edx opcode should clear whole rdx register:

xor     edx, edx //  31D2        
dec     rdx      //  48FFCA 

...这个运算code只需要5个字节。

... this opcode takes only 5 bytes.

编辑:

亚历克斯找到另一种解决方案:

Alex find another solution:

mov     rdx, -1  // 48C7C2FFFFFFFF

...这个运算code只需要7个字节。
但如何告诉编译器使用更短的运code(不使用DB)?

... this opcode takes only 7 bytes. But how to tell compiler to use shorter opcode (without using DB)?

...

什么是速度更快,更重要的是节约?

推荐答案

还有另一种选择,7个字节,编码 MOV RDX,-1 :48C7C2FFFFFFFF

There's an alternative, 7-byte, encoding of mov rdx, -1: 48C7C2FFFFFFFF.

您可以尝试写指令为 MOV RDX,DWORD -1 在code,以帮助编译器/汇编在使用这种较短的编码。

You can try writing the instruction as mov rdx, dword -1 in the code to aid the compiler/assembler in using this shorter encoding.

这篇关于放入小数字到64位x86寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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