Simulation (Stage 3.1) -- Specifying the start and end of our code |
There are three common tasks associated with each task we will perform with the SDS simulator
As an absolute minimum, you could get the simulator
EXPORT START START: EXPORT mycode mycode: MOVE.W A, D0 ADD.W B, D0 MOVE.W D0, C TRAP #15
However the next page segment shows how to set up some code to do the equivalent operations, but yet code can be reused in all future programs.
The approach to achieve this requires two steps
The startup.i file contains the following lines of code
section code .EXPORT START START: .IMPORT STKTOP MOVEA.L #STKTOP, SP ; (Set the stack pointer) JSR mycode ; mycode(); TRAP #15 ; Operating System Call DC.W $63 ; roughly equivalent to "C" exit() DC.W $0 ; will stop the program from running away
; IMPORTANT -- There is no END statement for "startup.i" (why not?)
The START statement achieved 3 different things
.IMPORT STKTOP MOVEA.L #STKTOP, SP ; (Set the stack pointer)
prepare the STACK POINTER register (SP) for subroutine/function calls using the JSR (Jump to SubRoutine) instruction. The assembly language directive .IMPORT means that the information is not present in the source file being assembled but will be known during the linking stage. In actual fact the label STKTOP is defined as part of the memory specification file. For more information on stack operations read the appropriate chapters of HVZ.
TRAP #15 ; Operating System Call DC.W $63 ; roughly equivalent to "C" exit() DC.W $0 ; will stop the program from running away
introduce what is known as a TRAP or as a Software Interrupt (SWI). This instruction is essentially a "custom illegal instruction" causing the processor to "crash" unless special steps are taken to "handle" the TRAP. Further information on interrupts can be found in HVZ and in Laboratory 3.
If you look inside the file startup.i you will see several lines of code making use of a register FP. This register (actually a mnemonic for address register A6) plays an important role in allowing a programmer to efficiently and effectively handle parameters and variables using the processor's memory stack. The register is used heavily in implementing the virtual device discussed in Laboratory 2. The register plays no role during Laboratory 1.
![]() |
Last modified: July 01, 1996 07:41 PM by M. Smith.
Copyright -- M. R. Smith