AT&T mov 指令

mov src , dst

只有确定的事物才能 从一个地方移动到另一个地方。通常mov子hi零可以

移动一个立即数单元到一个通用寄存器

移动一个立即数到内存

一个通用寄存器数据到另一个通用寄存器

一个段寄存器到一个通用寄存器

一个通用寄存器到控制流寄存器

一个控制流寄存器到一个通用寄存器

一个通用寄存器到一个debug 寄存器

一个debug 寄存器到一个通用寄存器

一个内存位置到一个通用寄存器

一个内存位置到一个段寄存器

一个通用寄存器到一个内存位置

一个段寄存器到一个内存位置

 

移动一个立即数到内存或者寄存器

Immediate data is directly specified in the instruction code statement, and cannot be changed during
runtime

movl $0, %eax # moves the value 0 to the EAX register
movl $0x80, %ebx # moves the hexadecimal value 80 to the EBX register
movl $100, height # moves the value 100 to the height memory location

在寄存器直接移动数据,注意寄存器的大小

movl %eax, %ecx # move 32-bits of data from the EAX register to the ECX register
movw %ax, %cx # move 16-bits of data from the AX register to the CX register

 

在内存和寄存器之间移动数据

使用label 在寄存器和内存间移动数据

movl value, %eax

movl %ecx, value

利用偏移量定位内存位置

The way this is done is called indexed memory mode. The memory location is determined by the
following:
A base address  基地址
An offset address to add to the base address  偏移地址
The size of the data element  数据单元大小
An index to determine which data element to select  数据单元标号


The format of the expression is
base_address(offset_address, index, size)
The data value retrieved is located at
base_address + offset_address + index * size
如果某个位置为空,代表为0

 

value 和 offset 的值必须是一个寄存器,size可以是一个立即数。

movl $2, %edi
movl values(, %edi, 4), %eax

 

使用放在寄存器中的间接地址

除了存放数据之外,寄存器还能够用于记录内存地址,当寄存器存放了一个内存地址是,他代表了要给指针。

通过指针来访问内存的数据,呗称为间接寻址。

While using a label references the data value contained in the memory location, you can get the memory
location address of the data value by placing a dollar sign ($) in front of the label in the instruction. Thus
the instruction

使用$ 符号,取得label的内存地址。 使用()包裹寄存器,代表使用寄存器中的地址,而不是寄存器
movl $values, %edi # 把value的地址放到edi寄存器中。

movl %ebx, (%edi) # 把ebx中的数据,放到edi存放的内存地址中去。
movl %edx, 4(%edi) # 把ebx中的数据,放到edi存放的内存地址 +4 的地址中去。
movl %edx, -4(&edi) # 把ebx中的数据,放到edi存放的内存地址 -4 的地址中去。





 

posted @ 2022-08-12 14:42  zzas12345  阅读(167)  评论(0编辑  收藏  举报