
196 Assembly Language Programming for the 68000 Family
SP —
+ $08
+ $0C
+ $10
+ $14
+ $18
15
Opt
12
Type Saved Access Level
Condition Codes
Argument Count
(Reserved)
Module Descriptor Pointer
Saved Program Counter
Saved Module Data Area Pointer
Saved Stack Pointer
Arguments (Optional)
Figure 20 Module call stack frame. (Courtesy of Motorola, Inc.)
Rn specifies the register to beloaded with the saved module’s data pointer
obtained from the stack. If SP is specified, this restored value is overwrit
ten by the updated value of SP. Rn would normally be chosen to match
the register specified by the module entry word. A nice feature of the
RTM is that it increments the stack pointer by the number of arguments
that were specified in the CALLM.
CAS and CAS2 The 68020 provides two new instructions that are ex
tensions to the mechanism provided by the test and set instruction, TAS.
Before you continue, it would be a good idea to review the TAS in
struction covered in Chapter 12. The TAS instruction only provides a
binary-type operation on a lock—in other words, the lock is set or it isn’t.
The compare and swap with operand instructions, CAS and CAS2, have
a much greater functionality. Their general forms are:
CAS Dc,Du,<ea>
CAS2 DC1:Dc2,Dul:Du2,(Rnl):(Rn2)
Dc and Du represent the compare and update registers. The CAS
instruction first compares Dc and <ea>. If they are equal, the contents of
Du is placed in <ea>. If they are not equal, the contents of <ea> is copied
to register Dc. If you think about it, this is actually a test and set type of
operation. The entire operation is performed in an atomic fashion—no
other processor or interrupt routine can execute bus cycles while this
instruction is executing. A typical application of the CAS instruction
would be the implementation of a counting semaphore. What we want
to be able to do is to increment the value of a semaphore in such a
manner that no other process or interrupt routine interferes. Here is how
we would use the CAS instruction:
Kommentare zu diesen Handbüchern