0.2.3 Changes to Instruction Encodings

MASM 6.0 contains changes to the encodings for several instructions. In some cases, the changes help optimize code size.

Coprocessor Instructions

MASM 5.1 adds an extra NOP instruction before the no-wait versions of coprocessor instructions. MASM 6.0 does not. In the rare case that the missing NOP affects the timing, insert NOP.

Also, in .286 mode, MASM 6.0 does not prefix any 8087, 80287, 80387, or 80486 coprocessor instruction with FWAIT (unless the instruction is the WAIT form of an instruction that has a NOWAIT form). MASM 5.1 prefixes some of these instructions with FWAIT.

RET Instruction

If the operand to RET, RETN, or RETF is 0, MASM 6.0 uses the one-byte encoding. MASM 5.1 generates the three-byte encoding in this case. Thus, it is possible to suppress the epilogue generation but still specify the default size for the RET (NEAR or FAR), by coding the return as

RET 0

If the operand for RET, RETN, or RETF is an external absolute, MASM 6.0 generates the three-byte encoding. In this case, MASM 5.1 ignores the parameter and generates the one-byte encoding.

LEA Instruction with Direct Memory Operands

When the second operand to the LEA instruction is a direct memory operand (that is, the second operand does not contain registers), MASM 6.0 encodes the instruction as

mov reg, OFFSET directmem

This is smaller and faster than the equivalent LEA encoding that MASM 5.1 generates. This should not affect your MASM 5.1 code.

Arithmetic Instructions

If your program uses the arithmetic instructions ADC, ADD, AND, CMP, OR, SUB, SBB, and XOR, and the following conditions are also true:

Either AX or EAX is the first operand

A sign-extendable byte constant is the second operand

then the instructions are encoded in MASM 5.1 as ax/eax, imm16/32.

MASM 6.0 uses this encoding instead: rm16/32. imm8.

With the AX register, there is no size or speed difference between the two encodings. In the EAX case, MASM 6.0's encoding is two bytes smaller. The OPTION NOSIGNEXTEND directive provides the MASM 5.1 behavior.