简体   繁体   中英

How do assembly instruction differentiate between register, memory address, immediate value or offset parameter?

I've been wondering, are there some invisible op-codes or flags or anything that tells the assembly instruction how to treat its parameters? Am a little confused, since apparently the same instruction can operate with different type operands - registers, memory addresses, offsets and immediate values are supported.

There doesn't seem to be any extra specifics in the "textual representation" of the assembly program, but maybe there is difference in the binary, eg some bits are toggled so that the CPU knows which type of operand is used?

The instructions are encoded in the hardware. How this is exaclty done is CPU specific. On the x86 architecture, you have some bits which define what the operand adressing modes are. For more detail you should refer to the Intel programmers reference manual, where this is explained in detail.

Sometimes there are instructions with different opcodes and the same effect, in such a case, the assembler can choose one.

http://www.sandpile.org/x86/opc_rm.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM