Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was looking at the different instructions in assembly and I am confused on how the lengths of different operands and opcodes are decided upon.

Is it something you ought to know from experience, or is there a way to find out which operand/operator combination takes up how many bytes?

For eg:

push %ebp ; takes up one byte
mov %esp, %ebp ; takes up two bytes

So the question is:

Upon seeing a given instruction, how can I deduce how many bytes its opcode will require?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
754 views
Welcome To Ask or Share your Answers For Others

1 Answer

There's no hard and fast rule for x86 without a database as the instruction encoding is pretty complex (and the opcode itself can vary from 1 to 3 bytes). You can consult the Intel? 64 and IA-32 Architectures Software Developer’s Manual 2A document (Chapter 2: Instruction Format) to see how instructions and their operands are encoded:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...