For example, the usage of "[]" in assembly language

Source: Internet
Author: User
The usage of "[]" has been described in "FAQ". The reference is as follows:

1. Push dword ptr [024c1100] dual-word of the 024c1100 value of the pressure Stack
2. Valid values of CMP eax, [EBP + 14] eax-EBP + 14, which are not retained. The mark bit is used mainly.
3, CMP byte PTR [eax], 46-byte eax-46, look at the flag
4. Lea eax, [edx-02] returns the valid value of the edx-02 (an address value) to eax
5. mov ECx, [edX + 08] edX + 8 values are used as the address. The value pointed to by this address is given to ECx.

I have provided a few examples of my experiences. I have referred to some materials and my personal understanding.
-------------------------------------------------------------------------------
The mov command uses "[]"

1 -- mov [EDI], eax ---- assign the eax value (DWORD) to the value at the memory address EDI
2 -- mov [bp-02], DX --- assign the DX value (Word) to the value located at the memory address bp-02
3 -- mov ESI, [bp + 14] --- move the value of DWORD in memory address bp + 14 into the ESI register
4 -- mov eax, dword ptr [ebp-04] --- move the value of the DWORD size located in the memory address ebp-04 into the eax register
5 -- mov eax, dword ptr [0000003ah] -- put the value of DWORD size in memory address 3A into the eax register
6 -- mov Cl, byte PTR [34 h] -- put the value of byte in memory address 34 into the CL register
7 -- mov dx, word PTR [3eh] -- put the value of the word size at the memory address 3E into the DX register
8 -- mov eax, [00403045 H] -- read a 32-bit value from the memory address 403045
9 -- mov Al, byte PTR [eax + ECx] -- put the byte size value in the memory address eax + ECx into the Al register

The [] mark is used to take the value from the memory address between the brackets. It is only the value without the brackets. The register and memory address can also be used.

10 -- mov CX, [eax] -- move the value of the word size in the memory address eax into the Cx register
In mov CX, [eax], the processor first checks what value (= memory address) is contained in eax, then what value is contained in the memory address, and put this word (16-bit, because the target-cx-is a 16-bit register) is moved into Cx.
-------------------------------------------------------------------------------
"[]" Is used in CMP commands

1 -- cmp dword ptr [ebp-04], 00000007 -- compare the DWORD size value located in the memory address ebp-04 with 00000007
2 -- CMP byte PTR [Si], 00 -- compare the byte size value in memory address Si with 00

-------------------------------------------------------------------------------
"[]" Is used in the lea command

1 -- Lea Di, [bp-22] ---- give the valid value of the bp-22 (= memory address) to Di
-------------------------------------------------------------------------------
"[]" Is used in the test command.

1 -- Test byte PTR [bx + 08fd]
-- Logic the value of the byte size at the memory address bx + 08fd and determine whether the calculation result is 00

Misunderstanding is inevitable. please correct me!

MARK: in fact, "[]" is equivalent to a pointer. The content in it is an address rather than a value, even if it is a register.
Sender: qqj1228
Details:

There are basically the following situations:
1. "[]" inner placement immediate count
MoV eax, dword ptr [00403000 H]
Put dual-word data with a memory address of 403000 into eax for direct addressing.
2. "[]" inner register
MoV eax, dword ptr [EBX]
Put the content indicated by the address in EBX into eax for indirect addressing of registers.
MoV eax, dword ptr [eax + EDI]
That is to say, the result of adding the value in eax to the value in EDI as the memory address is put into eax, which is equivalent to mov eax, dword ptr [eax] [EDI], it is also a register indirect addressing.
3. "[]" inner register plus immediate count
MoV eax, dword ptr [EBX + 0ch]
That is, the result of EBX plus 0ch is used as the memory address, and the content to which it points is put into eax, which is the relative addressing of registers.
It can also be equivalent to mov eax, dword ptr 0ch [EBX].
4. "[]" inner register multiplied by the immediate number
MoV eax, dword ptr [EDI * 4]
That is, add the content pointed to by the new address obtained by multiplying the address in EDI into eax to address the register proportional addressing.
The above is my understanding. If there are any mistakes, I hope you can correct them.

 

Question: To Ftb:
Sender: lianzi2000
Details:

To Ftb:
What you said is not accurate. in [], whether it is an immediate number, a register, or an expression, it is equivalent to a variable in advanced language, that is, an address. the actual operand is the content stored on the address. for example:
CMP byte PTR [eax], 46

Instead of comparing eax values with 46, we use a byte stored on the memory address specified by DS: [eax] to compare it with 46. similarly, push dword ptr [024c1100] is to press the dual-word stored in the memory address 024c1100 into the stack, rather than the number 024c1100 itself into the stack.

Although it is an address in [], it is not right to say it is a pointer. in advanced languages, the so-called pointer means that the content of the variable is an address. for example, we store a character 'C' at the memory address 00478030. Assume that the description in C is:

Char my_char = 'C ';

Therefore, the variable my_char corresponds to address 00478030, and [00478030] is a character variable,
MoV Al, [00478030]
The character 'C' is stored in Al.

If any

Char * p_char;

In this case, the variable p_char also corresponds to another address, which is assumed to be 00478158. [00478158], which is a pointer variable. The content stored before the value assignment is unknown. If there are:

P_char = & my_char;

At this time, the content stored in memory 00478158 is 00478030, and the character 'C' is stored in memory 00478030. This is the relationship between the pointer and the variable name.

For details, refer to my compilation experiences.

A special command is Lea, which means to load a valid address. Its operand is the address, so
Lea eax, [edx-02]
Instead of placing the value of the memory address specified by the [edx-02] To eax. the result is that both [eax] and [ebx-02] represent the same address.

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.