There has been some confusion about the values stored in the word-size ACK variables (H-Z and H2-Z2) which can hold values from 0 to 65535 (16-bit unsigned).
The ACK macro editor does an integer conversion to two's complement when displaying values; for example, if you type
SET A = 32767
in the macro editor, the line will display as entered, but if
you type
SET A = 65535
you will get
SET A = -1
in response. However, this is the only circumstance under which this conversion takes place. The value is still stored internally as 65535 and will be treated as such.
As I have spent more time experimenting and poking through the code, it seems to be fairly consistent in that negative numbers are not supported for variable and constant values.
Small variables (A-G, A2-G2) can hold from 0 to 255, while large variables (H-Z, H2-Z2) can hold from 0 to 65535.
It is not possible to type in a negative value for a parameter in a macro (it is not decoded correctly), and more specifically, it is not possible to subtract two positives and come up with a negative, for example:
SET A = 1 - 2
will result in A=0, not A = -1.
----
An exception to this: Because integer addition rolls over, you can set two's complement equivalent values and *pretend* they are negative for certain operations. For example, if you set L = 65535 (which the macro editor will display as "-1"), and then do
SET A = 3
SET A = A + L
you will get A = 2 in response, as if you had done SET A = A + (-1). However, this is the only place this works I am aware of.
If you do compares (> or <), the values are always treated as unsigned, so if L = 65535 and A=1,
IF (A > L)
will evaluate as false (1 is not greater than 65535), and not true as it would if L was truly -1.
Handling of negative values in ACK macros
Moderators: Ice Cream Jonsey, joltcountry
-
- Posts: 223
- Joined: Sun Jan 25, 2009 2:17 am
- Location: Dallas, TX