MoV & Lea
Zhou yinhui
Note:CodeIn the gas style, the L in movl and Leal is the gas suffix, indicating that the Operation count is of the "double" type. You can simply convert it into an int. I translated mov into "loading", which is close to the charm of "copying", rather than "moving"
1,Movl count register
Load the instant count to the specified register, such as movl $0x1234.% eax loads the hexadecimal 0x1234 to eax.
2,Movl register
Load the register content into another register. For example, movl % EBX and % eax copy the content in the register EBX to eax.
3,Movl memory register
Load the content in the memory into registers, such as movl (% EBX) and % eax. First, EBX reads a value and uses this value as the memory address, load the actual content to eax in memory
4,Movl instant memory
Load the immediate number to the memory. For example, movl $0x1234, (% EBX) First reads a value from EBX and uses this value as the memory address, then load the hexadecimal number 0x1234
5,Movl register memory
Load the content in the Register into the memory. For example, movl % EBX, (% eax) First reads a value from eax and uses the value as the memory address, load the values in EBX to the memory address.
Have you noticed? I did not list "movl memory" because it is illegal. to load the content in the memory to another memory segment, you need to transfer the register.
In addition, we noticed that code similar to (% eax) in the mov command indicates "using the calculated value as the memory address, the content at this address ". Then movl-12 (% EBX, % ECx, 4), % eax should be understood as: load the content (* P) pointed to by the pointer P into eax, where P points to the address of 4 * ECx + ebx-12, note that the load to eax is * P
If I want to express the following: "load the pointer P value into eax, where P points to the address 4 * ECx + ebx-12. Note: P is loaded into eax. What should I do? This is what Lea should do.
Lea is short for Load Balancing tive address. It loads a valid address, that is, "load an address to a register ".
1,Leal instant register
Load the number of immediately into the Register, such as Leal $0x1234, % eax and movl $0x1234, % eax have the same effect
2,Leal Address Register
Load the address to the register. For example, Leal M and N load the valid address of m to n. The effect can be understood as n <-- & M
Here are several examples:
Leal (% EBX), % eax: it loads (% EBX) Valid addresses in the memory into eax, but unfortunately (% EBX) is an indirect addressing, the valid address is saved in EBX, so this code has the same effect as movl % EBX and % eax.
Leal 2 (% EBX), % eax: where the valid address of the indirect addressing 2 (% EBX) is % EBP + 2, the meaning of this code can be understood: first, extract a value from EBX, add this value to 2, and then load it to eax.
Leal-12 (EBX, ECx, 4), % eax:
Have you noticed? There is no "Leal register", because it is impossible to remove the address from the register.
In addition, do not be confused by "addresses" and "* P". At the Assembly level, they are just "Numbers", for example:
Leal (% EBX, % EBX, 4), % eax
Assuming that the value in EBX is m, the above Code is only used to calculate 5 * m and put the result into eax. (Calculating 5 * m in this way saves some time than using Mul commands)