Getting Started
The following is a quick introduction to 68000 assembly language programming with EASy68K.
An assembly language program consists of:
labels - User created names that mark locations in a
program.
opcode - Specific instructions the microprocessor can
perform.
operands - Additional data required by some
instructions.
directives - Commands to the assembler.
macros - A user created collection of source code that
may be easily reused when writing a program.
comments - User created strings of text used to
document a program.
Each line of an assembly language program contains a combination of the following four fields.
Label Field
A label is used to identify a location in a program or a memory location by
name. Instructions or directives that require a location may use a label to
indicate the location. A label normally begins in the first column of the line.
It must be terminated with a space, tab or a colon. If a colon is used it does
not become part of the label. If a label does not start in the first column it
must be terminated with a colon. Only the first 32 characters of the label are significant.
Two types of labels are available: Global and Local. A global label may be
referenced from anywhere in the program. As such, global labels must be a unique
name. Global labels should start with a letter and be followed by letters,
numbers or underscores. Local labels may be reused in a program. Local labels
must start with a dot '.' and be followed by letters, numbers or underscores.
Global labels define the boundaries of a local label. When a local label is
defined it may only be referenced from code above or below the local label until
the next global label is encountered. The assembler creates a unique name for
local labels by appending the local label name to the preceding global label and
replacing the dot with a colon ':'. Only the first 32 characters of the
resulting name are significant.
Operation Field
The operation field follows the label field. If must be separated from the
label by at least one space or tab. If no label is present on the line there must be at
least one space or tab before the operation. Operations may be 68000 opcodes, assembler
directives or macro calls.
Operand Field
Operands contain extra information required by the item in the operation
field. Not all operations required extra information so an operand may not be
required. The operand field must be separated from the operation field by at
least one space or tab.
Comment Field
The last item on the source line is a comment area. User entered text is
placed here to document the program. The assembler ignores everything in the
comment field. The comment field must be separated from the previous field by at
least one space or tab.
For example:
label opcode operand comment
.Loop ADD D0,D1 Add two numbers
BMI
.Loop Loop
while negative
Assembly language programming requires direct interaction with the
microprocessor. The 68000 microprocessor contains eight data registers D0
through D7. Data registers are general purpose. They may be thought of as 8 bit,
16 bit or 32 bit
integer variables. There are eight address registers A0 through A7. Address
registers are 32 bits long. They are most commonly used to reference variables.
The status register (SR) contains status flags that indicate the results of
comparisons. The EASy68K simulator displays the registers of the 68000 as:
The following program will display the text "Hello World" and the number contained in D1. This is the program as it appears in the editor.
What it's all about:
ORG $1000
the program will load into address $1000
ORG $1000 defines
where the program will be located in memory. Dollar sign '$' indicates a
hexadecimal number. The remaining blue text on the line is comment.
* Display HELLO message
Lines that begins with an asterisk '*' are comments.
START
MOVE #14,D0 put text
display task number in D0
START is a label. The START label is referenced by the END directive in the last
line in the program. It is used to indicate where the program should begin
execution.
MOVE is the opcode, #14,D0 is the operand. The MOVE instruction moves the number
14 into data register D0. The '#' sign in front of the 14 indicates an immediate
or literal value. Without the '#' the instruction would get the contents of address 14 and put it in register D0.
LEA HELLO,A1
load address of string to display into A1
LEA loads the address of HELLO into address register A1. A1 now points to the
string at the address defined by the HELLO label.
TRAP #15
activates input/ouput task
TRAP #15 is used to run Simulator I/O routines (tasks) that are built into the
Sim68K simulator. The task number to run is in register D0. In this case the
task number is 14 which tells Sim68K to display the null terminated string pointed to by
register A1. See Simulator I/O in this help for a
complete list of TRAP #15 tasks.
The next three lines of code display the number 12345678.
MOVE.L
#12345678,D1 put a number in D1 so
we can display it
MOVE
#3,D0 task
number 3 in D0
TRAP
#15
display number in D1
The following two lines of code are used to stop a program. They
tell the simulator to halt.
MOVE.B
#9,D0
TRAP
#15
Halt Simulator
HELLO DC.B
'Hello World',$D,$A,0
null terminated string with newline
This line defines a text string named HELLO. DC.B defines constant bytes. The
text string is enclosed in single quotes. $D is carriage return, $A is line feed
and 0 is the null terminator.
END START
END indicates the end of the assembly program. START is the name of the label
where the simulator will begin running the program.
To run the program click the Assemble Source button on the
toolbar
If errors are detected error messages will be displayed at the bottom of the editor window. Double click on an error message to highlight the line of code in the source. Error messages are also added to the listing file (.L68 extension) if the option is selected to create it (default). Source files have a default extension of (.X68). Files that may be executed by the simulator have an extension of (.S68).
If no errors occur, click the Execute button and the program is loaded into the 68000 simulator Sim68K.
To run the program click the Run button on the toolbar.
The output
of the program is displayed.
See the EASy68K EXAMPLES folder for more example programs. More examples are also available at www.easy68k.com