The exclamation mark, !, is a BASIC operator to read or change doublewords in memory. In this context it is pronounced 'pling', 'bang' or, rarely, 'shriek'. It is somewhat equivalent to PEEK and POKE statements in other dialects of BASIC.
|Availability||Present in all original versions of BBC BASIC.|
|Syntax||BASIC I-V|| <num-var> = [<num-var>]|
|Token (hex)||BASIC I-V|| |
|Description||BASIC I-V|| If there are two operands, |
In the first form,
In the second form, the value assigned to
|Associated keywords|| |
! is an operator providing access to the memory of the machine
running BASIC. It allows the contents of memory to be inspected or changed
one doubleword at a time. A doubleword is a unit of four bytes, and can
hold a value between-2,147,483,648 and 2,147,483,647 or between &00000000
and &FFFFFFFF. By contrast the
? operator acts on
! can be either a
unary or binary operator. This doesn't depend on whether it is used
to PEEK or POKE, but is a syntactic convenience to help with
handling data structures.
If used as a unary operator, for example
!osword_block%, then the single operand is used as the
If used as a binary operator, for example
osword_block%!1, then the two operands are added together to
form the effective address. The first operand, conventionally the base
address, must not be a constant. The second operand is the offset,
typically a constant offset into a MOS control block.
Whether unary or binary, the operator will either read or write to memory,
depending on whether it is evaluated as an expression, or assigned a value.
In the latter case the whole [<num-var>]
serves as an lvalue, or <num-var>.
!osword_block% = target% sets the doubleword at
the address given by
osword_block%, to the value of
result% = osgbpb_block%!5 fetches the doubleword five to
eight bytes up from
osgbpb_block%'s value, and returns it to
The binary operation is the highest priority operation in any expression.
A%!PAGE+4 reads the word at
and then adds 4 to it.
A%!(PAGE+4) reads the word at
Doublewords in BBC BASIC are signed and little-endian: the byte at the
effective address holds the units place, the next one up holds the 256s
place, and so on. The whole doubleword is stored in two's-complement form
when the value is negative. If a fractional number is assigned to the
! operator, it is rounded toward zero.
The BBC Microcomputer User Guide is peppered with warnings about the use of
$. They are not to be used
to access memory-mapped devices or the system's internal variables - at
least, not in published programs. The relevant addresses may change or
disappear on different machines and MOS versions, or the program may find
itself running on the other side of the Tube! The MOS offers a
comprehensive API to access system functions in a portable way.
The address space in which
! operates is the one BASIC chooses
to provide for
!. Normally this is the address space of the
processor running BASIC. The BASIC program appears in this space, between
TOP, but as mentioned above,
well-behaved programs must not alter it.
BAS128 for the B+ and Master puts the 6502
address space from 0 to &FFFF, and adds an extended space between &10000 and
&1FFFF. This is made of the four slots of sideways RAM and contains the
user's program, variables and memory blocks. The MOS cannot access this
space (unless its own extended addressing system is enabled) and machine
code definitely cannot run in it although it can be assembled there with
OPTions 4 to 7.
-- beardo 04:43, 11 October 2007 (BST)