3.3.2 Defining Register Types with ASSUME

Beginning with MASM 6.0, you can use the ASSUME directive with general-purpose registers to specify that a register is a pointer to a certain size of object. For example:

ASSUME bx:PTR WORD ; BX is word pointer until further

; notice

inc [bx] ; Increment word pointed to by BX

add bx, 2 ; Point to next word

mov [bx], 0 ; Word pointed to by BX = 0

.

. ; Other pointer operations with BX

.

ASSUME bx:NOTHING ; Cancel assumptions

In this example, BX is specified to be a pointer to a word. After a sequence of using BX as a pointer, the assumption is cancelled by assuming NOTHING.

Without the assumption to PTR WORD, many instructions need a size specifier. The INC and MOV statements from the examples above would have to be written like this to specify the sizes of the memory operands:

inc WORD PTR [bx]

mov WORD PTR [bx], 0

When you have used ASSUME, attempts to use the register for other purposes generate assembly errors. In the example above, while the PTR WORD assumption is in effect, any use of BX inconsistent with its ASSUME declaration generates an error. For example,

; mov al, [bx] ; Can't move word to byte register

You can also use the PTR operator to override defaults:

mov ax, BYTE PTR [bx] ; Legal

Similarly, you can use ASSUME to prevent the use of a register as a pointer or even to disable a register:

ASSUME bx:WORD, dx:ERROR

; mov al, [bx] ; Error - BX is an integer, not a pointer

; mov ax, dx ; Error - DX disabled

See Section 2.3.3 for information on using ASSUME with segment registers.