,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 15
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
4-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)

,ce
DECLARATION SECTION

All constant, type, variable, and procedure names must be declared before being used. This chapter describes each of the declaration sections available in OmegaSoft Pascal.

Before covering the declaration sections it is appropriate to present the number types available in OmegaSoft Pascal.

,ce
NUMBERS

OmegaSoft Pascal recognizes integer (signed fixed point), hex (unsigned fixed point) and real (signed floating point) numbers.  Hex numbers may be represented in hexidecimal (0-9 and A-F) form or binary (1's and 0's) form. In addition, integer and hex numbers may be used to form byte (unsigned fixed point) numbers.

INTEGERS

Normal integers are positive and negative whole numbers ranging from -32768 to 32767. A minus sign (-) precedes a negative integer, a plus sign (+) may precede a positive integer, but has no effect.

Longintegers are positive and negative whole numbers ranging from -2147483648 through 2147483647. Minus and plus signs are allowed in the same manner as normal integers. A longinteger is an integer that is out of the integer range, or an integer followed by an "L" with no intervening space.

Examples :  0   0L   32000  -4317   3435L  30000000

HEX

Hex numbers are formed by using the decimal digits 0 through 9 and the letters A through F preceded by a dollar sign ($). The range for hex numbers is $0 through $FFFF.

Hex numbers may also be represented by using the decimal digits 0 and 1 preceded by a percent sign (%).

Longhex numbers have a range of $0 through $FFFFFFFF. A longhex number is a hex number that is out of the hex range, or a hex number followed by an "L" with no intervening space.

Examples : $0   $3AFF   $400L  %1011110000100

BYTES

Byte numbers are formed by prefixing a pound sign (#) in front of an unsigned integer or hex number. Only the least significant byte of the integer or hex number will be used. Byte numbers and byte variables are identical to character numbers and character variables, byte and char are synonyms.

Examples : #0   #255  #$FF   #%10001111
,pg
,ce
NUMBERS

REALS

Real numbers have a range of approximately 2.7E-20 to 9.2E18 and a resolution of approximately 7 digits. Note that due to the algorithms used the runtime routines will not convert the ascii representation of a real number into internal binary format outside of the range 5E-19 to 5E18. This restriction does not apply to the compiler, which uses IEEE format and then converts to the AMD9511 format used by the 6809 runtime.

Examples : 0.0   0.0L   3E15  3.14159   3.14159E+5

AUTOMATIC CONSTANT TYPE CONVERSION

Type conversions of certain constants is performed to allow clearer entry of numeric values. For instance, in a byte expression, hex and integer constants are allowed. The following four values are all equivalent :

 #$d  #13  $d  13

In a similar manner, hex constants can be used in integer and longinteger expressions, and integer constants can be used in hex and longhex expressions. As another example, to increment a pointer by four (a hex expression) :

 p := p + 4 ;

is allowed. There is a command line option that will generate a warning for each line where a conversion like this takes place. These types of conversions do not take place in declarations, such as in array index declarations :

 array [#1 .. #10] of integer     array [1 .. 10] of integer

In the first case, a byte index is used, in the second an integer is used. The same is true in constant declarations.

CUMULATIVE NUMBER SYNTAX

digit-sequence = digit {digit}
unsigned-integer = digit-sequence
unsigned-real = unsigned-integer ( . unsigned-integer 
                         [(e | E) signed-integer] |
                          (e | E) signed-integer)
hex-digit = (digit | A | B | C | D | E | F)
hex-number = ( $ hex-digit {hex-digit} | % (0 | 1) {(0 | 1)} )
byte-number = # (unsigned-integer | hex-number)
signed-integer = [(+ | -)] unsigned-integer
signed-real = [(+ | -)] unsigned-real
long-integer/hex/real = ( hex-number | signed-integer |
                          signed-real ) ( L | l )
,pg
,ce
NUMBERS

Pictorial diagram for signed-real :
 

     +
 
                unsigned-integer      .    unsigned-integer

     -


                 e             +

                                         unsigned-integer

                 E             -


,ce
LABEL DECLARATIONS

The label declaration is used to define to the compiler those unsigned-integers to be used as destinations for a GOTO statement. Note that this section does not define where the label will be, only that the designated values may be used as a label.

label-declaration = label unsigned-integer {, unsigned-integer} ;

Examples : label 10 ;    label               const
                           1, 2, 3, 4, 5 ;     loop1 = 1 ;
                                               loop2 = 2 ;
                                             label
                                               loop1, loop2 ;

,ce
CONSTANT DECLARATIONS

Constants are identifiers that are assigned an unchanging value. Constant identifiers are preferred over the use of numbers within a program. OmegaSoft Pascal has a very useful extension which allows a constant to be any constant-valued simple expression (see Chapter 5 for details of simple-expression syntax).

The type of the simple expression must be boolean, character, integer, longinteger, hex, real, string, or pointer.

The following types and operators and functions will remain constant if the operands are constants :

,in .21
Not, Or, Eor, and And  operator for boolean, character, integer, hex. 

Unary negation for integers, longintegers, and real. 

Addition, Subtraction and Multiply for character, integer, and hex. 

Div, Mod, and Shift operators for character, integer, and hex.

Ord and chr functions. 

General type conversions when the parameter and result are boolean, character, integer, enumerated type, or hex.
,in 0
,pg
,ce
CONSTANT DECLARATIONS

constant-declaration = const identifier = constant 
                       {; identifier = constant} ;
constant = constant-valued-simple-expression

 
        const       identifier       =       constant

 
                                     ;
 

,ce
PREDECLARED CONSTANTS

These are predeclared identifiers having specific constant values, they include : 

false      - boolean with an ordinal value of 0
true       - boolean with an ordinal value of 1
maxint     - integer with a value of 32767
minint     - integer with a value of -32768
nil        - pointer or hex with a value of $0
maxlint    - longinteger with a value of 2147483647
minlint    - longinteger with a value of -2147483648
e          - real with a value of 2.7182818284
pi         - real with a value of 3.1415926535

,ce
TYPE DECLARATIONS

The type-declaration part is used to assign a type to an identifier, or to create a new type out of existing types, either user defined, or predeclared.

In this chapter we will also describe how the various types are stored in memory as variables an how they appear on the data stack during expression evaluation or when passed as parameters.

The simplest of the types are the ordinal types. Any of the ordinal types can be converted into a unique integer. The ordinal types include : boolean, character, enumerated, integer, hex, and subranges of those.

type-declaration = type identifier = type {; identifier = type};


      type         identifier        =         type

                                     ;


BOOLEAN

Boolean types represent logical values, either false or true. Boolean is a predeclared enumerated type :

boolean = (false, true)

such that in relational expressions : false < true.
,pg
,ce
TYPE DECLARATIONS

Boolean variables are stored as one byte. The most significant 7 bits of the byte must be zero. If the least significant bit is zero, then it is false, else it is true. When boolean values are used in expressions they are in the B accumulator. When boolean values are passed as parameters by value or returned from a function they occupy one byte on the stack.

boolean-type = boolean
boolean-constant = (false | true | boolean-constant-identifier)

CHARACTER AND BYTE

A type defined as char (for character) or byte are exactly the same, char and byte are synonyms. Character values most often represent ascii data, but may represent any other data that can fit within one byte. Character variables are very useful for interfacing to byte-wide I/O ports by using absolute addressing, such as :

var  
  port1_ctrl : byte at $ff10 ;
begin
  port1_ctrl := %10010110 ; {initialize port}

Character variables are stored as one byte. When character values are used in expressions they are in the B accumulator. When character values are passed as parameters by value or returned from a function they occupy one byte on the stack.

character-type = char | byte
character-constant = (' character ' |
                      # (unsigned-integer | hex-number) |
                      character-constant-identifier)

Note that in a character-constant if it is necessary to represent the single quote (') it must be written twice ('').

Example : single_quote = '''' ;   at_symbol = '@' ;

ENUMERATED

An enumerated type declaration specifies the permissible values for that type. Enumerated types are most often used as selectors for case records and statements, or as values for array indexes. They have the advantage over using integers or bytes in that each value can be made to represent what it will actually be doing. Enumerated type values such as (current, voltage, phase) would be much more meaningful than using the values 0, 1, 2. 

Enumerated type variables are stored as one byte, the first value listed in the declaration is assigned to zero (unless forced to another value), the next to one, etc. When enumerated types are used in expression they in the B accumulator. If an enumerated type is passed as a parameter by value or returned from a function they occupy one byte on the stack. The starting value of an enumerated type may be forced to a non zero value by specifying the PREVIOUS value following a colon as the first element in the enumerated type. The previous value can either be an enumerated type or a byte constant. As an example, to start at 128 decimal, you could use : 
,pg
,ce
TYPE DECLARATIONS

abc = (:#127, onetwentyeight, onetwentynine ..... ) ;

The identifier names given are not actually used at run-time, therefore they cannot be read or written. Enumerated type is equivalent to the user defined scalar type as described in the Jenson and Wirth report.

enumerated-type = ( [ : constant] identifier {, identifier} )

The identifiers listed become constants of that enumerated type.

enumerated-constant = identifier

INTEGER

Integer variables are stored in two bytes, the most significant byte being at the lower address. When integers are used in expressions they are in the D accumulator. When integers are passed as parameters by value or returned from a function they occupy two bytes on the stack, the most significant byte being at the lower address.

integer-type = integer
integer-constant = signed-integer | integer-constant-identifier

HEX

Hex types are used to represent unsigned 16 bit values, such as addresses. Hex variables are stored in two bytes, the most significant byte being at the lower address. When hex values are used in expressions they are in the D accumulator. When hex values are passed as parameters by value or returned from a function they occupy two bytes on the stack, the most significant byte being at the lower address.

hex-type = hex
hex-constant = hex-number | hex-constant-identifier

LONGINTEGERS

Longintegers are used for applications where an integer does not have enough range and reals are not desirable due to either speed or roundoff problems. For instance in business applications where it is desirable to carry large money amounts and still have accurate cents amounts, reals are not suitable. A longinteger in ths application has a maximum value of $21,474,836.47 .

Longinteger variables are stored as four bytes, with the most significant byte being at the lowest address. When longinteger values are used in expressions, passed as parameters by value, or returned from a function, they occupy four bytes on the stack with the most significant byte being at the lowest address.

longinteger-type = longinteger
longinteger-constant = signed-integer |
                       longinteger-constant-identifier
,pg
,ce
TYPE DECLARATIONS

LONGHEX

Longhex variables are stored as four bytes, with the most significant byte being at the lowest address. When longhex values are used in expressions, passed as parameters by value, or returned from a function, they occupy four bytes on the stack with the most significant byte being at the lowest address.

Longhex variables are also compatible with pointers.

longhex-type = longhex
longinteger-constant = longhex-number |
                       longhex-constant-identifier

SUBRANGES

Subranges specify an ordinal type with a reduced range. Subranges are used to specify array indices, and in cases where you want to restrict the range of an ordinal type. When an assignment is made into a subrange variable (with the compiler S option enabled) extra code is generated to make sure that the value to be assigned does not fall outside of the subrange declaration. The following are examples of subranges of the ordinal types :

boolean :      false .. true
character :    'A' .. 'Z'     #0 .. #$1F
enumerated, with definition of (one,two,three) :   two .. three
integer : -32768 .. 32767    0 .. 10      -5 .. 5
hex : $0 .. $FF     $1000 .. $7FFF
longhex : $0L .. $FFL     $F30000 .. $F3007F
longinteger : -43000 .. 500L    1L .. 3000000

subrange-type = constant .. constant

Note that there is no actual subrange checking for subrange longhex and subrange longinteger even if the S option is enabled. These two type exist merely to allow longhex and longinteger to be used for array indices.

REALS

Real numbers are used for applications requiring a large range with limited resolution.

Real variables are stored as four bytes, with the most significant (exponent) byte being at the lowest address. When real values are used in expressions, passed as parameters by value, or returned from a function, they occupy four bytes on the stack with the most significant byte being at the lowest address.

Real value format : ( same as AMD9511 )
 
          exponent        mantissa
 
       M   
       S  EEEEEEE  MMMMMMMMMMMMMMMMMMMMMMM
 
 bit   31 30   24  23                    0

