What do square brackets mean in x86 assembly?

前端 未结 2 1237
逝去的感伤
逝去的感伤 2020-12-28 17:27

I\'m very new to assembly, and have some very basic questions.

What is the difference between these four commands?

mov ebx, eax
mov [ebx], eax
mov eb         


        
2条回答
  •  灰色年华
    2020-12-28 17:57

    You were missing the operand delimiter , in the instructions. I don't know (yet) of any assembler without it. I fixed that in the quotes.

    In x86 assembly some registers can be used as data registers or as address registers (a difference to other architectures). These registers are called GPRs ("General Purpose Registers"). They can contain 32-bit-values or 32-bit addresses. Their "names" are EAX,EBX,ECX,EDX,ESI,EDI,ESP,EBP.

    mov ebx, eax

    does move the value in EAX to EBX.

    mov [ebx], eax

    does move the value in EAX to the 32-bit DWORD value pointed to by the 32-bit address in EBX

    mov ebx, [eax]

    does move the 32-bit DWORD value pointed to by the 32-bit address in EAX to EBX

    mov [ebx], [eax]

    is an invalid instruction in 32-bit Intel assembly, because basic x86 assembly does not support two memory operands in one (two-operand) instruction. Newer instructions (SSE, AVX) with three or four operands are able to use more than one memory operand. This is a result of a more complex instruction encoding (using instruction prefixes).

提交回复
热议问题