Chapter
10
I
BASIC
Keywords
DEF
SEG
Statement
DEF
SEG[
=
address]
Assigns the current segment address. The segment address is
used by BLOAD, BSAVE, CALL, PEEK, POKE, and
USR.
Address
is a number in the range 0 to 65535, and may be speci-
fied as an integer or a hexadecimal value. If you specify a num-
ber outside this range, BASIC returns an “Illegal function call”
error and uses the previously set address.
If
you omit
address,
BASIC sets the current segment address
to
its data segment
(DS).
If you specify
address,
do
so
on a 16-byte boundary. BASIC
shifts the value to the left
4
bits, which is the same as multiply-
ing it by 16 decimal (10 hexadecimal).
Note:
BASIC does not check the validity of the result-
ant segment
+
offset address.
When you load BASIC, the data segment
(DS)
register is set
to
the address of BASIC’s workspace. You must, therefore, execute a
DEF SEG statement before executing BLOAD, BSAVE, PEEK,
POKE,
USR,
or
CALL (unless you used the
/M:
switch when you
loaded BASIC). Without the DEF SEG statement or the
iM:
switch, BASIC’s workspace could be destroyed.
If you execute a DEF SEG to change the DS register, you must
execute another DEF SEG to restore the DS register
to
BASIC’s
data segment (DS).
Separate DEF and SEG with
a
space. Otherwise, BASIC inter-
prets it as the variable DEFSEG.
138