本文介绍了了解ATT大会(立即)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说,我有以下装配线

lets say i have the following assembly lines

movl   $-1, %edi
movl   $1, %edx

我究竟在存入%EDI /%EDX寄存器。

What exactly am I storing into %edi/%edx registers.

基本上,如果我是这个code转换成C程序,我会被initalizing一些变量为-1和1,因为这就是我看到它,这就是我觉得我越来越糊涂了。

Basically if I were to convert this code into a C program, would I be initalizing some variables to -1 and 1 because that's how I see it and that's where I think I'm getting confused.

我明白,眼前=某个常数,但是这是什么意思?

I understand that immediate = "some constant" but what does that mean?

推荐答案

有四种方式来加载的东西到寄存器:

There are four ways to load something into a register:


  1. 立即值 - 在AT& T公司的汇编,这是使用 $号,并加载特定的值(数字)入册。需要注意的是数量不必是一个数值,它可能是,例如, MOVL $的printf,%eax中 - 这将printf的加载功能的地址到寄存器 EAX

  1. Immediate value - in AT&T assembler, that's using a $number, and it loads that particular value (number) into the register. Note that number doesn't have to be a numeric value, it could be, for example, movl $printf, %eax - this would load the address of the function printf into register eax.

从另一个寄存器, MOVL%eax中,%EDX - 我们现在有 EAX 值复制到 EDX

From another register, movl %eax, %edx - we now have eax value copied into edx.

从一个固定的内存位置, MOVL MYVAR,%EAX - MYVAR 的内容是 EAX

From a fixed memory location, movl myvar, %eax - the contents of myvar is in eax.

从另一个寄存器内存位置, MOVL(%eax中),%EDX - 现在, EDX 有任何32位值是在 EAX 的地址。当然,假设它实际上是一个好存储位置 - 如果不是,我们有一个段错误。

From a memory location in another register, movl (%eax), %edx - now, edx has whatever 32-bit value is at the address in eax. Of course, assuming it's actually a "good" memory location - if not, we have a segfault.

如果这是C code时,code可loook有点像这样:

If this was C code, the code may loook a bit like this:

1)

int x = 42; 

int (*printfunc)(const char *fmt, ...) = printf;

2)

int x = 1;  
int y = 2; 
..., 
x = y;     // movl  %eax, %edx

3)

int x = myvar;

4)

int x = *myptr;

编辑:
几乎一切,这是一个源移动指令也可以是算术运算,如加$ 3%EAX A源将在C相当于<$的C $ C> X + = 3;

Almost everything that is a "source" for a move instruction can also be a source for arithmetic operations, such as add $3, %eax will be the equivalent in C of x += 3;.

这篇关于了解ATT大会(立即)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:31