如何确定寄存器是从右向左加载还是从右向左加载 [英] How to determine if the registers are loaded right to left or vice versa

查看:210
本文介绍了如何确定寄存器是从右向左加载还是从右向左加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看gdb输出并查看汇编调用时,通常我可以找到一个使用硬编码值的命令来确定寄存器是从右向左加载还是从右向左加载.

When reviewing gdb output and looking at the assembly calls, usually I can find a command using hard-coded values to determine whether the registers are being loaded right to left or vice versa.

通常如下所示:

  sub     rsp, 16

  sub     16, rsp 

但是其他时候,看不到上面的值. 我所看到的只是像下面这样的呼叫:

But other times, no values like above are visible. All I see are calls like the following :

(gdb) disassemble
 Dump of assembler code for function main:
 0x0000000100000f54 <main+4>:    mov    $rdi,%r15
 0x0000000100000f59 <main+9>:    mov    $rsi,%r14
 0x0000000100000f60 <main+16>:   mov    $rdx,%r13
 0x0000000100000f67 <main+23>:   mov    $ecx,$r12d
 End of assembler dump.

如何确定值是从左到右处理还是从左到右处理?

How does one determine if values are processed left to right or vice versa?

推荐答案

通常,Gnu工具使用AT& T语法.您可以通过出现小符号(例如$前面的文字和%前面的寄存器)来确定它是AT& T语法.例如,此指令:

Normally, Gnu tools use AT&T syntax. You can tell that it is AT&T syntax by the presence of little symbols, like the $ preceding literals, and the % preceding registers. For example, this instruction:

sub    $16, %rax

显然是在使用AT& T语法.它从rax寄存器的值中减去16,然后将结果存储回rax.

is obviously using AT&T syntax. It subtracts 16 from the value in the rax register, and stores the result back in rax.

在AT& T语法中,目标操作数在右侧:

In AT&T syntax, the destination operand is on the right:

insn   source, destination     # AT&T syntax

还有Intel语法.这在Windows平台上无处不在,通常也可以作为Gnu/Linux工具的选项使用. Intel语法为未经修饰例如:

There is also Intel syntax. This is ubiquitous on Windows platforms, and usually also available as an option for Gnu/Linux tools. Intel syntax is unadornede.g.:

sub   rax, 16

与上面的AT& T指令相同,它从rax寄存器中的值减去16,然后将结果存储回rax寄存器中.

which is the same as the AT&T instruction above—it subtracts 16 from the value in the rax register, and stores the result back in the rax register.

在Intel语法中,目标操作数始终位于:

In Intel syntax, the destination operand is always on the left:

insn  destination, source     ; Intel syntax

要绝对确定您拥有哪个版本,您需要检查反汇编程序/调试器的设置,并查看其配置使用的语法,但是通常一目了然,这很简单通过查看是否存在象征性的装饰(AT& T语法的死胡同).

To be absolutely certain of which version you've got, you'd need to check the settings for your disassembler/debugger and see what syntax it is configured to use, but it's usually dead-simple to tell at a glance just by looking to see if the symbolic adornments are there (a dead give-away for AT&T syntax).

摘要:

  • 如果寄存器具有%前缀→AT& T语法→src, dst顺序.
  • 否则,未经修饰的寄存器→Intel语法→dst, src顺序.
  • If the registers have a % prefix → AT&T syntax → src, dst order.
  • Otherwise, unadorned registers → Intel syntax → dst, src order.

如果您最终以某种方式查看了不使用任何寄存器的代码(???),则另一个很好的启发式线索是Intel语法将在大小说明符之前(例如DWORDQWORDBYTE)添加到关联的操作数,而AT& T语法会将后缀(lqb等)附加到指令助记符本身.

If you've somehow ended up looking at code that doesn't use any registers (???), another good heuristic clue is that Intel syntax will prepend size specifiers (like DWORD, QWORD, and BYTE) to the associated operand, whereas AT&T syntax will append a suffix (l, q, b, etc.) to the instruction mnemonic itself.

这篇关于如何确定寄存器是从右向左加载还是从右向左加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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