DEF SEG Statement


To assign the current segment address to be referenced by a subsequent BLOAD, BSAVE, CALL, PEEK, POKE, or USR.


DEF SEG [=address]


address is a numeric expression within the range of 0 to 65535.

The address specified is saved for use as the segment required by BLOAD, BSAVE, PEEK, POKE, and CALL statements.

Entry of any value outside the address range (0-65535) results in an "Illegal Function Call" error, and the previous value is retained.

If the address option is omitted, the segment to be used is set to GW-BASIC's data segment (DS). This is the initial default value.

If you specify the address option, base it on a 16-byte boundary.

Segment addresses are shifted 4 bits to the left; so to get the segment address, divide the memory location by 16.

For BLOAD, BSAVE, PEEK, POKE, or CALL statements, the value is shifted left four bits (this is done by the microprocessor, not by GW-BASIC) to form the code segment address for the subsequent call instruction (see the BLOAD, BSAVE, CALL, PEEK, and POKE statements).

GW-BASIC does not perform additional checking to assure that the resultant segment address is valid.


10 DEF SEG=&HB800

Sets segment to screen buffer.


Restores segment to BASIC DS.


DEF and SEG must be separated by a space. Otherwise, GW-BASIC will interpret the statement DEFSEG=100 to mean, "assign the value 100 to the variable DEFSEG."