Pergunta

Can I do this in assembly mov eax, [ax] or must I specify the size mov eax, dword [ax].

Foi útil?

Solução

[ax] is not a valid 16-bit addressing mode. Change it to mov ebx, [bx] and you could do it. The ebx determines the size of the operation, so you wouldn't need to say dword. In 32-bit mode, [bx] is unlikely to be a "useful" address, but it's "valid" code. In 32-bit mode, mov al, [eax], mov ax, [eax] and mov eax, [eax] are all valid, and the sizes are determined by the size of the destination register, but you might want to say "byte", "word", or "dword" for clarity. In this(!) case, the sizes do not have to match.

FWIW, it is possible to use 32-bit instructions - and 32-bit addressing modes - in 16-bit code. The entire address needs to be within the segment limit - usually 64k - but mov eax, [eax + ecx * 4] is valid code. Nasm (or other "competent" assembler) will generate the required "operand size override prefix" and "address size override prefix" (0x66 and 0x67).

Don't be afraid to try these things... although it may not be clear WHY Nasm is refusing, and if Nasm DOES accept it that doesn't mean it will do what you intend...

Outras dicas

No, those operands don't match. On a 32-bit system, where you can access EAX, you would also have to use the same size for the address.

mov eax, [eax]

would replace the pointer in EAX with the value it points to.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top