BASIC stamp manual v2.2
4: BASIC Stamp Architecture – *, **
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 111
SYMBOL value1 = W0
SYMBOL value2 = W1
value1 = 1000
value2 = 19
value1 = value1 * value2 ' Multiply value1 by value2
DEBUG value1 ' Show the result (19000)
-- or --
value1 VAR Word
value2 VAR Word
value1 = 1000
value2 = - 19
value1 = value1 * value2 ' Multiply value1 by value2
DEBUG SDEC ? value1 ' Show the result (-19000)
The Multiply High operator (**) multiplies variables and/or constants,
returning the high 16 bits of the result. When you multiply two 16-bit
values, the result can be as large as 32 bits. Since the largest variable
supported by PBASIC is a word (16 bits), the highest 16 bits of a 32-bit
multiplication result are normally lost. The ** (double-star) instruction
gives you these upper 16 bits. For example, suppose you multiply 65000
($FDE8) by itself. The result is 4,225,000,000 or $FBD46240. The * (star, or
normal multiplication) instruction would return the lower 16 bits, $6240.
The ** instruction returns $FBD4.
SYMBOL value1 = W0
SYMBOL value2 = W1
value1 = $FDE8
value2 = value1 ** value1 ' Multiply $FDE8 by itself
DEBUG $value2 ' Return high 16 bits ($FBD4)
-- or --
value1 VAR Word
value2 VAR Word
value1 = $FDE8
value2 = value1 ** value1 ' Multiply $FDE8 by itself
DEBUG HEX ? value2 ' Return high 16 bits ($FBD4)
An interesting application of the ** operator allows you no multiply a
number by a fractional value less than one. The fraction must be
expressed in units of 1/65536. To find the fractional ** argument,
MULTIPLY HIGH: **
1
All
2
1
A
ll
2
1
All
2