Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
PAGE 38<br />
THE APPLE ORCHARD<br />
FALL <strong>1980</strong><br />
PASCAL OPERAND FORMATS<br />
or, The Secret Life of a Variable<br />
(or, Everything You Wanted to Know<br />
About Pascal Variables, But Couldn't Get<br />
Through To The Hotline To Ask)<br />
by<br />
Jo Kellner<br />
The <strong>Apple</strong> _hotline has received<br />
numerous calls about the internal<br />
structure of Pascal variables. This<br />
information can be very useful<br />
when sending data (especially<br />
complex data formats such as<br />
strings) to an assembly routine from<br />
a Pascal host program. This article<br />
describes a few of the more<br />
commonly used variable types. For<br />
a complete description of the more<br />
complex variables, including<br />
records and arrays, see pages 202<br />
through 204 of the <strong>Apple</strong> Pascal<br />
reference manual.<br />
Machine language (assembly)<br />
routines are commonly used<br />
when speed is critical, and when<br />
the code must access other<br />
assembly routines such as PROMs<br />
or 1/0 drivers which can't be reassembled<br />
as part of the program.<br />
Also, most single-bit operations are<br />
much easier to do in assembly than<br />
in Pascal.<br />
In the USCD Pascal system, it's a<br />
fairly simple matter to create short<br />
assembly programs which can be<br />
linked into a Pascal host program.<br />
In some cases, it may be sufficient<br />
to merely call the assembly routine;<br />
however, most routines require<br />
data in order to be useful. The<br />
means by which data is passed to or<br />
from these routines is called a "parameter/}.<br />
decimal 65535<br />
A parameter. is a temporary<br />
variable created by Pascal for the<br />
purpose of passing data to or from a<br />
subroutine. The term "formal<br />
parameter" implies that the<br />
address of the actual variable is<br />
passed to the subroutine as a<br />
parameter instead of its value.<br />
Certain types of variables may be<br />
passed by value, but any variable<br />
may be passed by name by simply<br />
declaring it to be a formal<br />
parameter (a VAR). Pascal does not<br />
allow parameters of variable length<br />
(with the exception of certain sets<br />
and long parameters) to be passed<br />
on the CPU stack, since this could<br />
exceed the stack capacity and crash<br />
the operating system, so these<br />
parameters are automatically used<br />
as formal parameters. A good<br />
explanation of the various ways of<br />
passing parameters may be found<br />
in Peter Grogono's book, " Programming<br />
in Pascal/}.<br />
Before delving into the details,<br />
let's define some terms and<br />
conventions which we'll use later<br />
on:<br />
BIT= a binary digit (0or1). A bit is<br />
the smallest unit of information<br />
which can be stored in a<br />
computer.<br />
NYBBLE = 4 bits (half a byte). A hexadecimal<br />
digit is one nybble<br />
(pronounced "nibble/}).<br />
hexadecimal FFFF < ....... memory ....-> 0000 addresses<br />
MSB<br />
LSB<br />
FIGURE 1<br />
< ........ byte ... ><br />
15 14 . . . 8 7 . . . . . 0 32767). By subtracting this<br />
positive value from 65536, the<br />
negative integer is revealed.<br />
Similarly, large positive integers are<br />
stored as a complementary<br />
negative numbers (remember<br />
Integer Basic). The sign bit (MSB) is<br />
0 if positive, 1 if negative.<br />
(see Figure 2)<br />
Example: the number 3 is represented<br />
in binary as:<br />
MSB<br />
LSB<br />
00000000 00000011<br />
However, -3 shows up as<br />
MSB<br />
LSB<br />
11111111 11111101<br />
which also reads as 65533 (or<br />
65536-3)!<br />
Integers may be passcu by value<br />
or as formal parameters.<br />
REALS<br />
Real numbers, in USCD Pascal,<br />
are floating point numbers in the<br />
range of +/ -1 .17550E-38 to +/ -3.402<br />
82E+38. Real numbers use four<br />
bytes (2 words). The binary representation<br />
is similar to the proposed<br />
IEEE standard for floating numbers:<br />
(See Figure 3, nex t page)