3
votes

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, e.g. some bits are toggled so that the CPU knows which type of operand is used?

1
The mnemonics are "overloaded", if you will, and refer to several different actual instructions depending on the types of the operands.Kerrek SB
@KerrekSB - I am mostly interested in whether different instructions hiding behind one name, like overloaded functions, or is it the same function with some extra data encoded that the CPU decodes in hardware on the fly?user2341104
Check out the Intel manual if you're interested in x86; this is described very clearly there. The initial bytes are fixed, but the operands are encoded in a systematic way in the subsequent bytes of the instruction.Kerrek SB
@KerrekSB - it may help if you point me where to look. I got 2 books on assembly, fairly new, one is 2005, the other 2009, but both don't seem to make it clear on this subject. But it is a lot of material, maybe I overlooked, that is why I am asking for pointers where exactly to look. Thanks... Ops, just saw your edit, will check the link out.user2341104
I would start with some instructions you are interested in most, and then go forward from there. It's rather complicated. I once wrote a dsissambler, and was trucking through the manual, and it takes some time to get used to it. :)Devolus

1 Answers

6
votes

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