Download Pascal/MT+ Programmer`s Guide
Transcript
Pascal/MT+ Programmer’s Guide
Absolute Variables
Variables evaluate to a long address. All jumps are relative to the current position in the code segment.
Literal constants of type integer are allocated one byte if the value falls in the range 0 to 255. Named
and declared integer constants always get two bytes.
Listing 9—3 demonstrates how you can use INLINE to construct compile-time tables. Note that the
ADDR of TABLE must be added to its offset. This is because ADDR does not give the address of
TABLE, due to additional code that recursion management produces. An extra eight bytes of code is
generated.
Note also that the procedure TABLE must be in the same module as the statement that takes the
ADDR of TABLE.
Listing 9-3 Using INLINE to Construct Compile-time Tables
PROGRAM demo_inline;
CONST
element = 3; {Third array element}
TYPE
Id_field = ARRAY [1. .8] OF CHAR;
Id_ptr = ^id_field;
pointerkludge = RECORD
CASE BOOLEAN OF
TRUE :(p : id_ptr);
FALSE: (l : longint);
END;
VAR
table_ptr : id_ptr;
p : pointerkludge;
offset : integer;
PROCEDURE table;
BEGIN
INLINE( ‘Digital ’ /‘Research’ /‘Software’);
END;
BEGIN (* Main Program *)
p.p := ADDR(table);
p.l := p.l + #14;
offset := sizeof(table_ptr^) * (element — 1);
p.l := p.l + long(offset);
table_ptr := p.p;
WRITELN(table_ptr^); (* Should write ‘Software’ *)
END. (* Main Program *)
Absolute Variables
You can declare a variable with an absolute address if you know the address at compile time. The
syntax for declaring ABSOLUTE variables is
<variable name> : ABSOLUTE [<address>]
The following examples are valid declarations of ABSOLUTE variables:
int : ABSOLUTE [$8000] INTEGER;
9-5