Language Levels: Compiler
Language Levels: Compiler
func
link A6,-4 1110101010110001110101
move 4(A6),temp(A6) 1010100010101010100001
lea 4(A6),A0 Assembler 0010001010101010101010
adda #2,A0 1010100010101001010101
...
Characteristics of Assembly Language
• Executable statements:
One of the processor’s valid instructions which can be translated into machine
code by the assembler
• Assembler Directives:
Assembler directives cannot be translated into machine code; they simply tell the
assembler things it needs to know about the program and its environment.
ORG $8000
MOVE.W #10,D6 ;repeat 10x
LOOP MOVEA.L #MESSAGE,A1 ;A1 points to message
TRAP #2 ;send message
SUBQ.W #1,D6 ;decrement count
BNE LOOP ;if not 0, do it again
TRAP #14 ;if 0, return to MON68K
MESSAGE DC.B 'Gary Grewal'
DC.B CR,LF ;begin a new line
DC.B 0 ;end with null byte
END
Assembler Directives
• In each case, the term <label> indicates a user defined label (symbolic name) that
must start in column 1, and
• <value> indicates a value that must be supplied by the programmer (this may be a
number, or a symbolic name that has a value).
EQU Directive
The EQU assembler directive simply equates a symbolic name to a numeric value. It
does not reserve space in memory!
Sunday EQU 1 The assembler substitutes the equated value for the
Monday EQU 2 symbolic name; that is,
.
. ADD #Sunday,D0 ⇔ ADD #1,D0
ADD #Sunday,D0
ORG CODE
MOVE #100,D0 008000 30
. Operation word
. 008001 3C
. 008002 00
ORG DATA Extension word
. 008003 64
.
009000
• The 68000 reserves the first 1024 bytes of memory for exception vectors.
• The starting address of program memory for the 68KMB is 800016. Therefore, you should
begin your programs with ORG $008000
DC Directive
The DC directive allows you to put a data value in memory at the time that the program
is first loaded. The DC directive takes the suffix .B, .W, and .L, depending on the size
of the value.
Memory Map
DS Directive
The DS directive is used to reserve one or more memory locations. The DS directive
takes a suffix .B, .W, and .L and an operand specifying the number of such quantities to
reserve.
The END directive indicates that the end of the code has been reached.
EQU $8000
Start MOVE #1,D2
.
.
.
.
.
.
END Start
The Software Used When Creating Assembly Programs
Listing File
(program1.lst)
EDITOR ASSEMBLER
program1.src
S-Record
(final.hex)
download to 68KMB
and execute
Example of a Simple Assembly Language
Program
The following program adds together two 8-bit numbers stored in the memory
locations called VALUE1 and VALUE2, and stores the sum in the memory
location called RESULT.
The source program is called ADD.SRC (The file extension .SRC is required by
the 68000 assemble.)
To assemble ADD.SRC:
Assembling ADD.SRC produces a text file, called ADD.LIS, that contains the original assembly-language
program after assembly, plus any error messages. The contents of ADD.LIS are shown below:
S0060000616464D0
S1138000103900009000123900009001D20013C111
S1098010000090024E4E38
S10590000C1846
S90380007C
S1 05 9000 0C18 46
B9
Data Bytes ⊕ 46
Checksum FF
LoadAddress
Byte Count Checksum
Record Type Calculation
Field Format
Program Execution
The following dump of a session was produced using a 68000 assembler.
The output of the simulator consists largely of the contents of the 68000’s
registers after each instruction is executed.
>md $8000
008000 10 39 00 00 90 00 12 39 00 00 90 01 D2 00 13 C1
008010 00 00 90 02 4E 4E 30 3C 00 64 00 00 00 00 00 00
008020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>md $9000
009000 0C 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00
009010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>tr
PC=008006 SR=2000 SS=00A00000 US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=00A00000 Z=0
D0=0000000C D1=00000000 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->MOVE.B $00009001,D1
Trace>
PC=00800C SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000018 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->ADD.B D0,D1
Trace>
PC=00800E SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000024 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->MOVE.B D1,$00009002
>md 9000
009000 0C 18 24 00 00 00 00 00 00 00 00 00 00 00 00 00
TRACE>
PC=008014 SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000024 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->TRAP #14
WARNING!
The previous program (to add together two 8-bit numbers stored in the memory
locations called VALUE1 and VALUE2, and store the sum in the memory
location called RESULT) will not assemble using A68K.
This assembler requires you to place greater-than signs (>) in front of the labels
VALUE1, VALUE2, and RESULT as shown below: