x86-64 指令“shrb %​​dil"是什么意思?意思? [英] What does the x86-64 instruction "shrb %dil" mean?

查看:50
本文介绍了x86-64 指令“shrb %​​dil"是什么意思?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 shr​​b 代表逻辑右移.通常它与两个参数一起使用,shr​​b amount, %register.但是,在我查看的代码中,它没有使用移位量 - 只指定了一个寄存器:

I know that shrb stands for shift logical right. Usually it's used with two arguments, shrb amount, %register. However, in the code I'm looking at it does not use a shift amount - there is just a register specified:

shrb %dil

其中 %dil 代表 %rdi 的最低有效字节.

where %dil stands for the lower least significant byte of %rdi.

现在上面的命令是否暗示我们右移 1?你会怎么去发现这个?有没有办法以某种方式执行命令,看看会发生什么?该文档对于提供有关省略班次金额时会发生什么的信息没有帮助:https://docs.oracle.com/cd/E19253-01/817-5477/817-5477.pdf

Now does the command above imply that we shift right by 1? How would you go about finding this out? Is there a way to execute the command somehow and see what happens? The documentation wasn't helpful about providing information about what happens when one omits the shift amount: https://docs.oracle.com/cd/E19253-01/817-5477/817-5477.pdf

推荐答案

这是 AT&T/GAS 语法,与 Intel 语法有很大不同.在 Intel 语法中,等效指令为:

This is AT&T/GAS syntax, which is very different from Intel syntax. In Intel syntax, the equivalent instruction would be:

shr  dil, 1

它是 64 位长模式代码,将 edi 寄存器(指使用 dil 助记符)的最低 8 位右移 1 位.(目标操作数的)最低有效位被移入进位标志(CF),最高有效位被清除.(shr​​ 的标准行为.)

It is 64-bit long mode code that shifts the lowest 8 bits of the edi register (referred to using the dil mnemonic) right by 1 bit. The least significant bit (of the destination operand) is shifted into the carry flag (CF), and the most significant bit is cleared. (Standard behavior for shr.)

请注意,在您的代码中,shr​​ 助记符带有 b 后缀.这表明这是一个byte 大小的操作.Intel 语法使用操作数之一(egDWORD PTR)上的注释来消除歧义,而 AT&T 语法使用指令后缀:b 用于byte,w 为字,l 为长字,q 为四字等

Notice that, in your code, the shr mnemonic is suffixed with a b. This indicates that it is a byte-sized operation. Whereas Intel syntax uses annotations on one of the operands (e.g., DWORD PTR) to disambiguate, AT&T syntax uses instruction suffixes: b for byte, w for word, l for long-word, q for quad-word, etc.

在这种情况下,b 后缀实际上是可选的,即使在 AT&T 语法中也是如此,因为目标操作数是一个 8 位寄存器,这使得指令没有歧义.但是,Gnu 工具通常会为所有指令添加后缀以保持一致性,即使没有歧义.这可能是您的代码的来源.

In this case, the b suffix is actually optional, even in AT&T syntax, since the destination operand being an 8-bit register makes the instruction unambiguous. However, Gnu tools will generally add the suffixes to all instructions for consistency, even where there is no ambiguity. This is probably where the code you have came from.

此外,在 AT&T 语法中,shr​​sarshl 指令通常会在为 1 时省略移位量.换句话说,将其写为以下技术上是正确的:

Also, in AT&T syntax, the shr, sar, and shl instructions often omit the shift amount when it is 1. In other words, it would be technically correct to write this as:

shrb  $1, %dil

但是我见过的大多数工具都不会使用这种形式,尤其是 Gnu 反汇编器.(请注意 AT&T 和 Intel 语法之间的另一个区别:目标和源操作数颠倒.)

but most tools that I've seen won't use this form, especially the Gnu disassemblers. (Notice here another difference between AT&T and Intel syntax: the destination and source operands are reversed.)

移位量为1时省略可能是历史原因.x86 上的每条移位指令实际上有三种不同的编码:一种是按常量 1 移位,一种是按立即数移位,另一种是按 cl 寄存器的内容移位.直到 286 才引入立即移位编码,这就是为什么有一个单独的(较短的)移位编码.如今,您可以将 shift-by-1 编码为 shift-by-immediate-1,但没有理智的汇编程序会这样做.尽管如此,AT&T/GAS 语法在符号中保留了这一历史遗产.

The omission of the shift amount when it is 1 may be for historical reasons. There are actually three different encodings for each of the shift instructions on x86: one that shifts by a constant 1, one that shifts by an immediate, and one that shifts by the contents of the cl register. The shift-by-immediate encoding wasn't introduced until the 286, which is why there is a separate (shorter) encoding for shift-by-1. Nowadays, you could encode shift-by-1 as shift-by-immediate-1, but no sane assembler would do that. Still, the AT&T/GAS syntax preserves this historical legacy in the notation.

这篇关于x86-64 指令“shrb %​​dil"是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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