ASSEMBLY LANGUAGE COURS PART IX by Mark van den Boer
System Control instructions
In this part of the course the last group of instructions will be
explained. This group of instructions deals with the supervisor-
mode and are therefore sometimes referred to as system control
instructions. To remind you: the S-bit in the SR (status
register) of the 68000 determines whether the 68000 is in
supervisor-mode or not. Many of these instructions deal with so
called exceptions. Exception is another word for interrupt and
these are used to force program control immediately to a specific
routint exception handler routine. Exceptions are used to detect
situations that are urgent and need to be handled directly.
Therefore every exception has a vector assigned to it. This
vector is a pointer to a routine which performs some action which
should be taken when such an exception occurs. The exception
vectors are located in the first 256 longwords of memory.
Instruction: CHK
Syntax: CHK <ea>,Dn
Data sizes: word
Condition codes affected:
X not affected
N Set if Dn is less than zero, cleared if <ea>
less than Dn, in all other cases undefined
Z
V
C always undefined
Addressing modes allowed:
Source:
Dn
(An)
(An)+
-(An)
w(An)
b(An,Rn)
w
l
w(PC)
b(PC,Rn)
#
Destination:
Dn
Function: Compares the contents of the effective address operand
with the data-register. If the data register is less
than zero (the data register is always considered to be
a signed word) or greater than the contents of <ea>,
then an exception occurs. The pointer to this
exception-routine is located at address $18. This
instruction is used to check if a data register is
within a range. It is often used by high-level
languages such as PASCAL to perform array-bound
checking.
Examples:
Instruction Before After
CHK #50,D0 D0=45 D0=45
No exception occured, if D0 had been 51
or greater then an exception would have
occured.
Instruction: MOVE USP (privileged instruction)
Syntax: MOVE USP,An or MOVE An,USP
Data sizes: long
Condition codes affected:
X
N
Z
V
C not affected
Addressing modes allowed:
See syntax
Function: As you all should know, the 68000 has in fact two A7
registers. One A7 register is used when in supervisor-
mode, the other when in usermode (this is: not in
supervisor-mode. It is sometimes desirable for a
program which is executing in supervisor mode to know
the value of the usermode A7-register. This instruction
provides a way to obtain and change the value of A7
usermode-register.
Example:
Instruction Before After
MOVE USP,A6 A7user=$12345678 A7user=$12345678
A6 =$00000000 A6 =$12345678
A7sup =$87654321 A7sup =$87654321
Instruction: RESET
Syntax: RESET (privileged instruction)
Data sizes: none
Condition codes affected:
X
N
Z
V
C not affected
Function: Reset all external devices. A device can be a chip like
the 6850.
Instruction: RTE (privileged instruction)
Syntax: RTE
Data sizes: none
Condition codes affected:
none
Function: Every exception is terminated by this instruction. It
can be compared to RTS. The only difference is that RTE
will restore the SR in addition. Note that an
exception-routine has the responsibility to save
registers if this is important.
Instruction: STOP (privileged instruction)
Syntax: STOP #
Data sizes: word
Condition codes affected:
All set as a direct result of the operand
Addressing modes allowed:
Source:
#
Function: Stop execution of a program until an exception occurs.
The operand stored in the SR. Note that with the
operand a minimum interrupt level can be determined.
With this instruction it is possible to wait for a
videochip interrupt to occur.
Example:
STOP #%0010011000011111
Wait for an exception with a priority of 6 or 7 to
occur and set the XNZVC-bits.
Instruction: TRAP
Syntax: TRAP #
Data sizes: # must be >=0 and <=15
Condition codes affected:
X
N
Z
V
C not affected
Function: This instruction generates an exception. The operand
indicates an exception number. The vectors for the
exceptions are located at addresses $80 to $BC. This
instruction is mainly used to allow programs that
execute in user-mode to call supervisor-mode routines.
This way a user can be given a number of specific
functions. In the ST trap vectors 2, 14 and 15 are used
for GEM, BIOS and XBIOS functions. In the case of the
ST the TRAP-instructions is preceded by instructions
that put function numbers and parameters for these
functions on the stack. This way it is possible to
assign groups of functions to one trap-vector.
Note that when calling a TRAP in user-mode the
stackpointers change (supervisor-mode and user-mode,
remember??). Thus, the MOVE USP instruction can be used
to retrieve parameters that had been put on the stack.
Instruction: TRAPV
Syntax: TRAPV
Data sizes: none
Condition codes affected:
none
Function: When the V-bit is set an exception occurs. The
exception vector is located at address $1C. When the V-
bit is clear nothing happens. This instruction can be
used by high-level languages to inform the user that an
overflow error has occured.
Disclaimer
The text of the articles is identical to the originals like they appeared
in old ST NEWS issues. Please take into consideration that the author(s)
was (were) a lot younger and less responsible back then. So bad jokes,
bad English, youthful arrogance, insults, bravura, over-crediting and
tastelessness should be taken with at least a grain of salt. Any contact
and/or payment information, as well as deadlines/release dates of any
kind should be regarded as outdated. Due to the fact that these pages are
not actually contained in an Atari executable here, references to scroll
texts, featured demo screens and hidden articles may also be irrelevant.