Write a disassembler at least once. It's much easier than you think it is (even with X86) --- it's essentially a file format parser --- and very illuminating.
It's also much easier to decode x86 instructions when you look at them in octal instead of the hexadecimal that most tables use, since both the main opcode map and ModRM/SIB are organised in a 2-3-3 layout: http://reocities.com/SiliconValley/heights/7052/opcode.txt The 8080/8085/Z80 instruction sets also look much better in octal: http://www.z80.info/decoding.htm
x86 Disassembly
21–29 of 29 posts
Re: x86 Disassembly
#22Write a disassembler at least once. It's much easier than you think it is (even with X86) --- it's essentially a file format parser --- and very illuminating.
It's also much easier to decode x86 instructions when you look at them in octal instead of the hexadecimal that most tables use, since both the main opcode map and ModRM/SIB are organised in a 2-3-3 layout: http://reocities.com/SiliconValley/heights/7052/opcode.txt The 8080/8085/Z80 instruction sets also look much better in octal: http://www.z80.info/decoding.htm
It does not suprise me that something so simple would be so well overlooked (or, at least, "forgotten"). I wonder if I ever would have figured this out from my own readings and experiments. Doubtful.
Great tip!
Re: x86 Disassembly
#23Earlier quoted context omitted.
It's also much easier to decode x86 instructions when you look at them in octal instead of the hexadecimal that most tables use, since both the main opcode map and ModRM/SIB are organised in a 2-3-3 layout: http://reocities.com/SiliconValley/heights/7052/opcode.txt The 8080/8085/Z80 instruction sets also look much better in octal: http://www.z80.info/decoding.htm
I had no idea! This is very cool.
Re: x86 Disassembly
#24Write a disassembler at least once. It's much easier than you think it is (even with X86) --- it's essentially a file format parser --- and very illuminating.
I'm currently writing one in JavaScript of all languages, just to prove it works. also, it's true multi-platform ;)
Re: x86 Disassembly
#25Earlier quoted context omitted.
It's also much easier to decode x86 instructions when you look at them in octal instead of the hexadecimal that most tables use, since both the main opcode map and ModRM/SIB are organised in a 2-3-3 layout: http://reocities.com/SiliconValley/heights/7052/opcode.txt The 8080/8085/Z80 instruction sets also look much better in octal: http://www.z80.info/decoding.htm
This comment validates all the time I have "wasted" reading HN over the years. It does not suprise me that something so simple would be so well overlooked (or, at least, "forgotten"). I wonder if I ever would have figured this out from my own readings and experiments. Doubtful. Great tip!
As an aside, ARM opcodes are (mostly) hex-structured with 4-bit fields, while MIPS, POWER, and SPARC are not amenable to any standard number base except binary (5- and 6-bit fields.)
Re: x86 Disassembly
#26Re: x86 Disassembly
#27Why does `push eax` perform "much faster" than the following? sub esp, 4 mov DWORD PTR SS:[esp], eax A brief skim of Intel's "Software Developer’s Manual" (particularly ch. 6 on stacks), didn't seem to find an answer. While hitting the ALU just for `sub` might be an extra step, doesn't hitting RAM make that a drop in the bucket? (`sub` may account for less than 1%?) Or is there some caching going on, so RAM may be up…
It's a lot smaller (1 byte vs 6), which means less space spent in the cache and decoder, reducing cache misses and decode bandwidth. The x86 also has a dedicated "stack engine" since the Pentium M (but not suprisingly, absent in NetBurst), which contains an adder and copy of the stack pointer to handle push/pop operations. This is faster than using the general-purpose ALUs and memory read/write ports, and also frees…
Re: x86 Disassembly
#28Earlier quoted context omitted.
I had no idea! This is very cool.
This is seriously exploding my brain. Thank you for posting it.
You are clearly intelligent, well educated, etc. and blah blah blah.
Yet, you somehow missed that.
If you can explain why, it would probably be something we could all learn from. At the very least, it would be interesting.
Is it because you learned x86 before you learned octal and never really reexamined the encoding?
(The PDP-11 machine code also looks best in octal, btw.)
Re: x86 Disassembly
#29Why does `push eax` perform "much faster" than the following? sub esp, 4 mov DWORD PTR SS:[esp], eax A brief skim of Intel's "Software Developer’s Manual" (particularly ch. 6 on stacks), didn't seem to find an answer. While hitting the ALU just for `sub` might be an extra step, doesn't hitting RAM make that a drop in the bucket? (`sub` may account for less than 1%?) Or is there some caching going on, so RAM may be up…
http://www.agner.org/optimize/microarchitecture.pdf
§7.7.