: I havn't used absolute addressing before and I dont understand how
Absolute addressing has certain advantages, one is meant to overcome pascal's strong typing by being able to convert between different data types. Is basically multiple variables denoting the same memory location.
var w:word;
b:array[0..1] of byte absolute w;
What it means is that
w and
b are the same but of different type. So if you modify
w then
b will change accordingly and vice versa. Is useful when quick access is needed to
w's high or low byte, instead of calling a function ( hi(w) or lo(w) ) can be simply referring to
b[0] or
b[1]. Another thing is that can be used for string manipulations (would speed up and simplify certain operations, since string ops. are quite slow)
var s:string;
l:byte absolute s;Is this example
l denotes the length of
s. Why, because how strings are stored in memory, for example
The string: "absolute" is stored as:
Offset: 0 1 2 3 4 5 6 7....
8 a b s o l u.... The first byte at offset 0 indicates the length of the string ( that's why a string's length can only be 255 at most since a byte cannot store a higher value than 255 ). Also, declaring a string variable will eat up 256 bytes of memory (length_marker + 255 reserved bytes ), so for large structures is always good to declare the strings at their biggest expected length (e.g. string[15] <-- will limit the length to 15, takes 16 bytes of memory), however this is not an issue with 32 bit protected-mode programs only for dos real-mode. Back to the example, declaring a byte absolute to the string will refer to offset 0 which is the length marker. Now instead of calling
length(s); we can directly work with
l, same thing, only faster because is no calls are involved. Also is a quick way to truncate or concatenate
ss:=copy(s,1,5);
-OR-
l:=5;
s:='';
for i:=1 to 15 do {<-- slow string operation}
s:=s+'X';
-OR-
l:=15; {set length }
for i:=1 to l do {<-- fast indexing }
s[i]:='X';
Note, that care with the coding must be considered, since the speed comes with a trade off, the possibility of creating bugs. But when you'll get the hang of it this won't be an issue anymore. Another use of "absolute" would be mapping directly the memory, I'm not getting into this because it can be used only for real-mode dos applications, tinkering with memory in protected-mode could easily lead to an app. killer: "general protection fault".
: the 'write#32' statements work. what is the benefit of using these?
: is there a 'simpler' way of doing it without using it?
This is my "bad" habit of coding

, it comes from my tendency to optimize for no good reason and the laziness of typing...
Is just inserting ASCII codes to create certain effects, is comes from the way the video interrupt handles the data passed to it by the
write routine, so:
write(#13#10,'blah..blah..blah...');
-Is equivalent to:
writeln;
write('blah..blah..blah...'); {Saved a few keystrokes and a function call }
Here are a few ASCII codes you could insert:
#7 - Will produce a beep sound
#8 - Back space { equivalent to: gotoxy(wherex-1,wherey); }
#13#10 - Carriage return + Line feed
#32 - Sapce -OR- ' '
Also can be used to display some nonprinting chars. like: #9, #11 etc.