a***@drrob1.com
2015-03-13 23:54:09 UTC
Hi. I decided to see if I can get the LinkList code example in the
tutorial to work using Stony Brook M2 under WinXP. And I wanted to
print out the dynamic addresses. This is what I wrote, assuming all
needed IMPORT statements are there:
PROCEDURE AdrToHexStr(adr : ADDRESS;
VAR INOUT OutStr : ARRAY OF CHAR);
CONST ASCZERO = ORD('0');
ascA = ORD('A');
VAR i,j,h,L : CARDINAL;
Str20 : STR20TYP;
adrcard : ADRTOCARD;
BEGIN
i := 0;
L := CARDINAL(adr); (* won't compile *)
L := ORD(adr); (* won't compile *)
L := TRUNC(adr); (* won't compile *)
L := VAL(CARDINAL,adr); (* won't compile *)
REPEAT (* until L = 0 *)
h := L MOD 16;
IF (h <= 9) THEN
Str20[i] := CHR(h + ASCZERO)
ELSE
Str20[i] := CHR(h -10 + ascA)
END;
INC(i);
L := L DIV 16;
UNTIL L = 0;
j := 1; (* first posn is a space to leave room for sign char *)
OutStr[0] := ' ';
REPEAT (* until i = 0 *)
DEC(i);
OutStr[j] := Str20[i];
INC(j);
UNTIL i = 0;
OutStr[j] := 0C;
END AdrToHexStr;
As my first attemtp to cast the address to a cardinal failed
miserably, I used a variant record, as below.
PROCEDURE AdrToHexStr(adr : ADDRESS;
VAR INOUT OutStr : ARRAY OF CHAR);
CONST ASCZERO = ORD('0');
ascA = ORD('A');
TYPE ADRTOCARD = RECORD
CASE :BOOLEAN OF
TRUE: A : ADDRESS;
| FALSE: C : CARDINAL;
END; (* CASE *)
END; (* RECORD *)
VAR i,j,h,L : CARDINAL;
Str20 : STR20TYP;
adrcard : ADRTOCARD;
BEGIN
i := 0;
adrcard.A := adr;
L := adrcard.C;
REPEAT (* until L = 0 *)
h := L MOD 16;
IF (h <= 9) THEN
Str20[i] := CHR(h + ASCZERO)
ELSE
Str20[i] := CHR(h -10 + ascA)
END;
INC(i);
L := L DIV 16;
UNTIL L = 0;
j := 1; (* first posn is a space to leave room for sign char *)
OutStr[0] := ' ';
REPEAT (* until i = 0 *)
DEC(i);
OutStr[j] := Str20[i];
INC(j);
UNTIL i = 0;
OutStr[j] := 0C;
END AdrToHexStr;
The variant record solution works. My question is this: why did all
of my attempts to cast the address to a cardinal fail?
Thanks,
Rob
tutorial to work using Stony Brook M2 under WinXP. And I wanted to
print out the dynamic addresses. This is what I wrote, assuming all
needed IMPORT statements are there:
PROCEDURE AdrToHexStr(adr : ADDRESS;
VAR INOUT OutStr : ARRAY OF CHAR);
CONST ASCZERO = ORD('0');
ascA = ORD('A');
VAR i,j,h,L : CARDINAL;
Str20 : STR20TYP;
adrcard : ADRTOCARD;
BEGIN
i := 0;
L := CARDINAL(adr); (* won't compile *)
L := ORD(adr); (* won't compile *)
L := TRUNC(adr); (* won't compile *)
L := VAL(CARDINAL,adr); (* won't compile *)
REPEAT (* until L = 0 *)
h := L MOD 16;
IF (h <= 9) THEN
Str20[i] := CHR(h + ASCZERO)
ELSE
Str20[i] := CHR(h -10 + ascA)
END;
INC(i);
L := L DIV 16;
UNTIL L = 0;
j := 1; (* first posn is a space to leave room for sign char *)
OutStr[0] := ' ';
REPEAT (* until i = 0 *)
DEC(i);
OutStr[j] := Str20[i];
INC(j);
UNTIL i = 0;
OutStr[j] := 0C;
END AdrToHexStr;
As my first attemtp to cast the address to a cardinal failed
miserably, I used a variant record, as below.
PROCEDURE AdrToHexStr(adr : ADDRESS;
VAR INOUT OutStr : ARRAY OF CHAR);
CONST ASCZERO = ORD('0');
ascA = ORD('A');
TYPE ADRTOCARD = RECORD
CASE :BOOLEAN OF
TRUE: A : ADDRESS;
| FALSE: C : CARDINAL;
END; (* CASE *)
END; (* RECORD *)
VAR i,j,h,L : CARDINAL;
Str20 : STR20TYP;
adrcard : ADRTOCARD;
BEGIN
i := 0;
adrcard.A := adr;
L := adrcard.C;
REPEAT (* until L = 0 *)
h := L MOD 16;
IF (h <= 9) THEN
Str20[i] := CHR(h + ASCZERO)
ELSE
Str20[i] := CHR(h -10 + ascA)
END;
INC(i);
L := L DIV 16;
UNTIL L = 0;
j := 1; (* first posn is a space to leave room for sign char *)
OutStr[0] := ' ';
REPEAT (* until i = 0 *)
DEC(i);
OutStr[j] := Str20[i];
INC(j);
UNTIL i = 0;
OutStr[j] := 0C;
END AdrToHexStr;
The variant record solution works. My question is this: why did all
of my attempts to cast the address to a cardinal fail?
Thanks,
Rob