Compiler Library/XL Reference Manual (32650-90029)

4- 17
HP Pascal/XL Example
{
This program calculates total appropriations by the
United States federal government for the years 1977-1979
}
$notes off$
$standard_level 'ext_modcal'$
program appropriations (output);
type
ascii_num_15 = { 15-digit numbers in ASCII }
packed array [1..15] of char;
nibble = 0..15; { Half a byte, holds a digit or sign }
packed_num_15 = { Holds 15 digits and sign }
crunched record
digits : crunched array [1..15]
of nibble;
sign : nibble;
end;
year_type = 1977..1979;
yearly_table = array [year_type]
of ascii_num_15;
const
yearly = yearly_table { Annual appropriations, in cents }
['046655980996406',
'050778229148999',
'056396083378825'];
var
zero : shortint;
year : year_type;
packed_sum, packed_temp : packed_num_15;
ascii_sum, ascii_temp : ascii_num_15;
procedure HPPACADDD; intrinsic;
procedure HPPACCVAD; intrinsic;
procedure HPPACCVBD; intrinsic;
procedure HPPACCVDA; intrinsic;
begin
zero := 0;
HPPACCVBD (packed_sum, 15, zero, 1); { Initialize sum }
for year := 1977 to 1979 do
begin
writeln (year:1, ' ', yearly [year]); { Echo annual data }
ascii_temp := yearly [year]; { Can't pass const as var }
HPPACCVAD (packed_temp, 15, ascii_temp, 15); { Convert ASCII to decimal}
HPPACADDD (packed_sum, 15, packed_temp, 15); { Add to sum }
end;
HPPACCVDA (ascii_sum, 15, { Convert sum to ASCI, }
packed_sum, 1); { suppressing plus }
writeln ('Total ', ascii_sum);
end.
HP FORTRAN 77/XL Example
C
C This program calculates total appropriations by the
C United States federal government for the years 1977-1979
C
$STANDARD_LEVEL SYSTEM