本文介绍了如何通过操作码确定是否需要ModR/M?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读ia-32指令格式,发现ModR/M是一个字节(如果需要),但是如何确定是否需要它,有人说它是由Opcode确定的,但是如何?我想知道细节,是否有一些有用的权威性文件解释这些细节?

I am reading the ia-32 instruction format and found that ModR/M is one byte if required, but how to determine if it is required, someone says it is determined by Opcode, but how? I want to know the details, and is there some useful and authoritative documents which explain the details?

推荐答案

Intel的vol.2手册详细介绍了每种指令的每种形式的操作数编码.例如仅采用著名的 add 指令的8位操作数大小版本有2个reg,rm表格; rm,立即表格;和add al, imm8

Intel's vol.2 manual has details on the encoding of operands for each form of each instruction. e.g. taking just the 8-bit operand size versions of the well-known add instruction, which has 2 reg,rm forms ; a rm,immediate form ; and a no-ModRM 2-byte short for for add al, imm8

Opcode    Instruction    | Op/En |  64-bit Mode | Compat/Leg Mode |  Description
04 ib     ADD AL, imm8   |  I    |   Valid           Valid         Add imm8 to AL.
80 /0 ib  ADD r/m8, imm8 |  MI   |   Valid           Valid         Add imm8 to r/m8.
00 /r     ADD r/m8, r8   |  MR   |   Valid           Valid         Add r8 to r/m8.
02 /r     ADD r8, r/m8   |  RM   |   Valid           Valid         Add r/m8 to r8.

在此之下,指令操作数编码¶表详细说明了上面Op/En(操作数编码)列中的那些I/MI/MR/RM代码的含义:

And below that, the Instruction Operand Encoding ¶ table details what those I / MI / MR / RM codes from the Op/En (operand encoding) column above mean:

Op/En   | Operand 1        | Operand 2     | Operand 3  Operand 4
RM      | ModRM:reg (r, w) | ModRM:r/m (r) |  NA        NA
MR      | ModRM:r/m (r, w) | ModRM:reg (r) |  NA        NA
MI      | ModRM:r/m (r, w) | imm8/16/32    |  NA        NA
I       | AL/AX/EAX/RAX    | imm8/16/32    |  NA        NA

请注意,"I"操作数形式未提及ModRM,因此没有之一.但MI确实有一个. (使用操作码表中的80 /0中的/0填充/r字段.)

Notice that the "I" operand form doesn't mention a ModRM, so there isn't one. But MI does have one. (With the /r field being filled in with the /0 from the 80 /0 in the opcode table.)

请注意,RM和MR的区别仅在于r/m操作数(可以是内存)是目标还是源.

Notice that RM and MR differ only in whether the r/m operand (that can be memory) is the destination or source.

这篇关于如何通过操作码确定是否需要ModR/M?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:32