3 ms·
There's a handy appendix in the NASM manual that's good for answering questions like this. It doesn't tell you anything that isn't in the data sheet, but it's m
by to3m 14y ago
There's a handy appendix in the NASM manual that's good for answering questions like this. It doesn't tell you anything that isn't in the data sheet, but it's more concise (the x86 data "sheet" is, like, 5 volumes, and must be 2,500 pages).
http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoca.html http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoca.html
From this you can see that many arithmetic and logic instructions have special encodings that use AL/AX/EAX as the destination. (You can also use the more general encoding to produce exactly the same instruction, but in more bytes.)
If you're working with AL/AX/EAX, then if you arrange for ESI and EDI to point into your source and dest buffers respectively, you can use LODS and STOS to fetch and store bytes. If your processing is working in a streaming-like fashion (and this isn't a bad idea, if you can arrange it) then you can fetch or store a bytes or dword, and bump the pointer, using one instruction that's 1 byte. Doing this with a MOV followed by an INC would be 2 instrutions and 3 bytes.
There is no short form for the [EBP] addressing mode, nor [EBP+reg], because you virtually always use fixed offsets with a base pointer. I think both of these end up as [EBP+0] or [EBP+reg+0], so you'll alwas waste an extra byte for the fixed displacement if you try to use EBP for something more general.
The rotate instructions have special encodings that take the rotate count in CL, since C is for count after all.
There's probably also a few more bits and pieces like the above, which was just what stuck in my mind from when I wrote code to generate x86 machine code directly. I just skimmed through the NASM doc to double check my memory.
I couldn't say whether using the shorter forms makes any realistic difference on real code these days, aside from the general 'fewer bytes = probably quicker' rule. But If you're trying to make EXEs that are 4K or less, as this guy seems to, I bet the little savings would add up.