Add; Subtract; Multiply - Parallax BASIC Stamp 2e Programming Manual

Table of Contents

Advertisement

A
: +
DD
2
1
2
e
2
2
e
S
: -
UBTRACT
2
2
1
e
2
2
e
M
: *
ULTIPLY
2
1
2
e
4: BASIC Stamp Architecture – +, -, *
The Addition operator (+) adds variables and/or constants, returning a 16-
bit result. Works exactly as you would expect with unsigned integers from
0 to 65535. If the result of addition is larger than 65535, the carry bit will be
2
2
sx
p
lost. If the values added are signed 16-bit numbers and the destination is a
16-bit variable, the result of the addition will be correct in both sign and
value. For example:
1
SYMBOL
Value1 = W0
SYMBOL
Value2 = W1
Value1= - 99
Value2= 100
Value1= Value1 + Value2
DEBUG Value1
-- OR --
2
2
Value1
VAR
sx
p
Value2
VAR
Value1= - 1575
Value2= 976
Value1= Value1 + Value2
DEBUG SDEC ? Value1
The Subtraction operator (-) subtracts variables and/or constants,
returning a 16-bit result. Works exactly as you would expect with
2
2
p
sx
unsigned integers from 0 to 65535. If the result is negative, it will be
correctly expressed as a signed 16-bit number. For example:
1
SYMBOL
Value1 = W0
SYMBOL
Value2 = W1
Value1= 199
Value2= 100
Value1= Value1 - Value2
DEBUG Value1
-- OR --
2
2
Value1
VAR
sx
p
Value2
VAR
Value1= 1000
Value2= 1999
Value1= Value1 - Value2
DEBUG SDEC ? Value1
The Multiply operator (*) multiplies variables and/or constants, returning
the low 16 bits of the result. Works exactly as you would expect with
2
2
unsigned integers from 0 to 65535. If the result of multiplication is larger
sx
p
WORD
WORD
WORD
WORD
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 67
' Add the numbers.
' Show the result (1).
' Add the numbers.
' Show the result (-599).
' Subtract the numbers.
' Show the result (99).
' Subtract the numbers.
' Show the result (-999).

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents