{ex1.source 01/02/08 nm -e ex1p.debugboo} $pagewidth 120, lines 44$ $standard_level 'os_features'$ $type_coercion 'representation'$ $tables on, statement_number on, code_offsets on$ $list_code on$ $optimize off$ {=============================================================== Disclaimer: This program has several sloppy coding practices that can (and have) led to problems. They were put in to help demonstrate program aborts ... I don't *really* code that way! --------------------------------------------------------------- Note: This program uses PRINT in an effort to avoid using the Pascal/XL I/O package (e.g., writeln). This shortens the amount of code emitted by the compiler, which makes it easier to use as a tool for teaching about Debug. --------------------------------------------------------------- Program description: Show access cost to variables above dp+8192 ("small_var") Show "anyvar" in Pascal. --------------------------------------------------------------- Exercise 1.1: How many instructions does it take to access "small_var"? (Hint: small_var is access in the outer block) Exercise 1.2: What is passed into "upshift"? (How many words of data, and what are they?) ===============================================================} program ex1; type byte = 0..255; {occupies 1 byte} good_failed = (failed, good); pac4 = packed array [1..4] of char; pac80 = packed array [1..80] of char; pac80_ptr_type = ^ pac80; var buf : pac80; {Big variables...} big_array : array [0..10000] of char; small_var : integer; Procedure debug; intrinsic; Procedure print; intrinsic; Procedure zap (anyvar xxx : integer; val : byte); forward; {*************************************************} procedure upshift (anyvar buf : pac80); { Purpose: Changes all lowercase characters in the buffer passed in to uppercase. The size of the buffer is magically passed in as a hidden parameter because we declared 'buf' as 'anyvar'. } var c : char; inx : integer; begin for inx := 1 to sizeof (buf) do begin { Note: we turn off range checking because a buffer of more than 80 bytes may have been passed in, and we don't want spurious aborts caused because Pascal/XL thinks we have an invalid index. } $push, range off$ c := buf [inx]; if (c >= 'a') and (c <= 'z') then begin {c is a lowercase letter} c := chr (ord (c) - ord ('a') + ord ('A')); buf [inx] := c; {c is now an uppercase letter} end; $pop$ {range} end; end {upshift proc}; {*************************************************} procedure zap (anyvar xxx : integer; val : byte); { Purpose: Zaps every byte in the variable passed in to the value specified by 'val'. The size of the variable is magically passed in as a hidden parameter because we declared 'xxx' as 'anyvar'. } var inx : integer; ptr : ^byte; begin ptr := addr (xxx); for inx := 1 to sizeof (xxx) do begin ptr^ := val; ptr := addtopointer (ptr, 1); end; end {zap proc}; {*************************************************} begin small_var := 1; {note the two-instructions needed to access var!} {Test the zap routine...} buf := 'now is the time to test zap'; zap (buf, ord (' ')); {blank out 'buf'} print (buf, -10, 0); {print first 10 bytes of buf} {Test the upshift routine} buf := 'CATsup'; upshift (buf); print (buf, -6, 0); end.