This test shows which is the most compact coding for various mnemonics. Savings may not be significant in a small piece of code, but over a whole program it can add up to a lot. The coding results may vary from assembler to assembler. Use the breakpoint SIZEOF_CODE and run to the test, then single-step through the code. Alternatively you can simply view the code without executing it. To do this use the menu item "inspect, codepane to view code at, procedure".
The following are the results using GoAsm which was used to assemble Testbug. You may well find that the assembler you use does not provide these savings. Try putting similar code in your own application and testing the assembler you use.
1. PUSHing a value between -80h and +7Fh can be done with two opcode bytes but outside these ranges requires 5 bytes.
2. MOVing any number to a 32 bit register requires 5 opcode bytes, MOVing any number to a 16-bit register requires 4 bytes, but MOVing a number to an 8-bit register can be done in 2 bytes.
3. A number of -1 takes 5 opcode bytes using MOV EAX,-1 but only 3 bytes when using XOR EAX,EAX and then DEC EAX.
4. There is a saving of one byte using INC ESI,ESI instead of ADD ESI,2 and DEC ESI,ESI instead of SUB ESI,2.
5. ADC, ADD, AND, CMP, OR, SBB, SUB and XOR using 32 bit registers are all significantly smaller when using a number between -80h and +7Fh. These are the opcode 83 short forms. GoBug disassembles these to show the negative value.
6. XOR EAX,EAX saves 3 bytes over MOV EAX,0
7. OR EAX,EAX, TEST EAX,EAX and AND EAX,EAX saves 1 byte over CMP EAX,0
8. CMP EAX,EAX (two bytes) can be used to set the zero flag.
9. JECXZ saves two bytes over OR ECX,ECX and JZ.
10. When addressing memory, using 32 bit or 8 bit registers will always result in smaller code than using 16-bit ones.
11. The last 5 lines of code are:-
MOV EAX,OFFSET DWORD_TESTER
12. This coding combined with the earlier results show that the smaller opcode forms apply from -80h to +7Fh when using CMP, ADD, SUB etc., but not MOV.
13. In some assemblers the last 2 lines of the code which do the same thing will be assembled using the same opcodes.