HIGH Operator Problem

ID Number: Q11535

4.00

MS-DOS

Problem:

The HIGH operator assembles incorrectly for negative numbers. For

example, the following program produces "00" instead of "PH":

_DATA SEGMENT WORD PUBLIC 'DATA'

DB HIGH (-1)

_DATA ENDS

END

Response:

The problem stems from the assembler performing 17-bit, signed

magnitude arithmetic internally, i.e., -1 is represented by 1 with

another bit saying that it is negative.

The HIGH operator is currently implemented as follows:

1. Take the high byte of the 16-bit argument.

2. If it is negative, take the two's complement.

This procedure produces the following results:

HIGH( -1 ) ==> HIGH( -0001H ) ==> - 00 ==> FFH + 1 ==> 00

HIGH( -32767 ) ==> HIGH( -7FFF ) ==> - 7F ==> 80H + 1 ==>

81H

The correct behavior would be to switch steps 1 and 2. This process

was implemented in the Macro Assembler Version 5.00.

A workaround to this problem is to avoid using the HIGH operator on

negative numbers and code the desired value directly.