13.6 MMX Instruction Operands


13.6 MMX Instruction Operands

Most MMX instructions operate on two operands, a source and a destination operand. A few instructions have three operands with the third operand being a small immediate (constant) value. In this section we'll take a look at the common MMX instruction operands.

The destination operand is almost always an MMX register. In fact, the only exceptions are those instructions that store an MMX register into memory. The MMX instructions always leave the result of MMX calculations in an MMX register.

The source operand can be an MMX register or a memory location. The memory location is usually a quad word entity, but certain instructions operate on double word objects. Note that, in this context, "quad word" and "double word" mean eight or four consecutive bytes in memory; they do not necessarily imply that the MMX instruction is operating on a qword or dword object. For example, if you add eight bytes together using the paddb (packed add bytes) instruction, paddb references a qword object in memory, but actually adds together eight separate bytes.

For most MMX instructions, the generic HLA syntax is the following:

      mmxInstr( source, dest ); 

The specific forms are

      mmxInstr( mmi, mmi );   // i=0..7      mmxInstr( mem, mmi );          // i=0..7 

MMX instructions access memory using the same addressing modes as the standard integer instructions. Therefore, any legal 80x86 addressing mode is usable in an MMX instruction. For those instructions that reference a 64-bit memory location, HLA requires that you specify an anonymous memory object (e.g., "[ebx]" or "[ebp+esi*8+6]") as a qword variable.

A few instructions require a small immediate value (or constant). For example, the shift instructions let you specify a shift count as an immediate value in the range 0..63. Another instruction uses the immediate value to specify a set of four different count values in the range 0..3 (i.e., four 2-bit count values). These instructions generally take the following form:

      mmxInstr( imm8, source, dest ); 

Note that, in general, MMX instructions do not allow you to specify immediate constants as operands except for a few special cases (such as shift counts). In particular, the source operand to an MMX instruction has to be a register or a quad word variable; it cannot be a 64-bit constant. To achieve the same effect as specifying a constant as the source operand, you must initialize a quad word variable in the readonly (or static) section of your program and specify this variable as the source operand.

Although HLA allows you to declare initialized 64-bit variables using the uns64, int64, and qword types, you'll discover that very few MMX instructions actually operate on 64-bit data operands; instead, they typically operate on an array of bytes, words, or double words. Because HLA provides good support for byte, word, and double word constant expressions, specifying a 64-bit MMX memory operand as a short array of objects is probably the best way to create this data. However, the MMX instructions that fetch a source value from memory expect a 64-bit operand. Therefore, you must declare such objects as qword variables. You can easily declare the objects as quad words and initialize them with bytes, words, and double words using the @nostorage attribute, e.g.,

 static      mmxDVar: qword; @nostorage;           dword $1234_5678, $90ab_cdef; 

Note that the dword directive above stores the double word constants in successive memory locations. Therefore, $1234_5678 will appear in the L.O. double word of the 64-bit value and $90ab_cdef will appear in the H.O. double word of the 64-bit value. Always keep in mind that the L.O. objects come first in the list following the dword (or byte, or word, or ???) directive; this is opposite of the way you're used to reading 64-bit values.

The example above used a dword directive to provide the initialization constant. However, you can use any data declaration directive, or even a combination of directives, as long as you allocate at least eight bytes (64-bits) for each qword constant. The following data declaration, for example, initializes eight 8-bit constants for an MMX operand; this would be perfect for a paddb instruction or some other instruction that operates on eight bytes in parallel:

 static      eightBytes: qword; @nostorage;           byte 0, 1, 2, 3, 4, 5, 6, 7; 

Although most MMX instructions operate on small arrays of bytes, words, or double words, a few actually do operate on 64-bit quantities. For such memory operands you would probably prefer to specify a 64-bit constant rather than break it up into its constituent double word values. This way, you don't have to remember to put the L.O. double word first and perform other mental adjustments. Of course, HLA fully supports 64-bit (and even 128-bit) numeric constants as initializers, so this is a trivial issue in HLA. Example:

 static      anotherEightBytes: qword := $1234_5678_9abc_def0; 




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net