TAL Programmer's Guide Data Alignment Addendum

TAL Misalignment Examples
TAL Programmer's Guide Data Alignment Addendum524967-003
4-6
Invalid Conversion of Odd-Byte String Addresses
Example 4-6. TAL Hashing Strings by Means of int Operations (Item 4)
Change this:
string .ext name;
int .ext name_as_ints = name;
int lth;
int checksum := 0;
while lth >= 2 do begin
checksum := checksum + name_as_ints; ! misalignment traps here
@name := @name[2];
lth := lth - 2;
end;
if lth > 0 then
checksum := checksum + (name '<<' 8);
To this:
string .ext name;
int lth;
int checksum := 0;
while lth >= 2 do begin
checksum := checksum + ((name[0] '<<' 8) lor name[1]);
@name := @name[2];
lth := lth - 2;
end;
if lth > 0 then
checksum := checksum + (name '<<' 8);
Example 4-7. TAL Appending a Single Zero Byte to a String (Item 7)
Change this:
! append a string, followed by single zero byte:
string .ext cur_end;
int .ext ender; ! wrong pointer type
cur_end ':=' some_text for n bytes -> @ender;
ender := 0; ! stores 2 bytes, gets misalignment trap,
! and round-down overwrites prior data byte
To this:
! append a string, followed by single zero byte:
string .ext cur_end;
string .ext ender;
cur_end ':=' some_text for n bytes -> @ender;
ender := 0;