4.2 Integer Operations

You often need to copy, move, exchange, load, and sign-extend integer variables in your MASM code. This section shows how to do these operations as well as how to add, subtract, multiply, and divide integers; push and pop integers onto the stack; and do bit-level manipulations with logical, shift, and rotate instructions.

Summary: The PTR operator tells the assembler the size of the operand.

Since MASM instructions require operands to be the same size, you may need to operate on data in a size other than the size originally declared. The PTR operator lets you do this. For example, you can use the PTR operator to access the high-order word of a DWORD-size variable. The syntax for the PTR operator is

type PTR expression

where the PTR operator forces expression to be treated as having the type specified. An example of this use is

.DATA

num DWORD 0

.CODE

mov ax, WORD PTR num[0] ; Loads a word-size value from

mov dx, WORD PTR num[2] ; a doubleword variable

You might choose not to use PTR, in contrast to this example. In that case, trying to move num[0] into AX generates an error.