4 transferring program control – Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual
Page 47

6Ć7
10 SET_MAGNITUDE(A%,0FEFE2222H)
(A% is replaced by 02222H)
Even if the result of the value field is more than 16 bits of
significance (all integer arithmetic is done internally as 32 bits), only
the lower 16 bits are loaded into the variable (single integer
variable). If the variable is a double integer variable, all 32 bits of the
value field are loaded into the variable.
Without the SET MAGNITUDE statement, the programmer would
need to sign extend 16Ćbit hex values into a 32Ćbit form.
For example, when the statement A% = 0FFFFH executes, BASIC
attempts to put the value 0000FFFFH into the variable A%. This
causes an overflow because the hex number is greater than 32767,
the largest single integer. When this happens, BASIC logs an error
and loads the variable A% with the greatest possible value (32767).
The variable A%, since it is a 16Ćbit value, will hold the quantity
0FFFFH, but it must be sign extended into a 32Ćbit form to be
handled internally and look like a number in the range 32767 to
Ć32768. Since all hex constants are not sign extended but assumed
to have leading zeros in the leading hex digits, 0FFFFH is too large.
Sign extending 0FFFFH would result in 0FFFFFFFFH, which is
expressed in 2's complement decimal format as the number -1.
Therefore, the statement A% = - 1 or A% = 0FFFFFFFFH would
properly load the value 0FFFFH into the variable A%.
6.4
Transferring Program Control
At times it may be necessary to transfer control to different sections
of a task depending on certain conditions (the value of a variable,
the occurrence of an event, etc.). BASIC provides the following
statements to accomplish this:
1. GOTO (GO TO) statement
2. ON/GOTO statement
3. GOSUB statement/RETURN statement
4. ON/GOSUB statement
6.4.1
GOTO (GO TO) Statement
The GOTO statement causes the statement that it identifies by line
number to be executed next, regardless of that statement's position
within the program. BASIC executes the statement at the line
number specified by GOTO and continues the program from that
point.
The following is the GOTO statement format:
GOTO line_number
or
GO TO line_number
where:
line number=
next program line to be executed; can be an integer constant or
integer expression. The specified line number can be smaller
(go backward) or larger (go forward) than the line number of the
GOTO statement.