Sunteți pe pagina 1din 19

ELET 31444

Embedded Controller Applications


68HC11 Assembly Language Review

Spring 2008

68HC11 Assembly Language Syntax


A program to be executed by the 68HC11 consists of a
set of lines.
Each line could contain an instruction or a directive
Instructions are commands that are actually executed
by the microcontroller.
Directives are not part of the 68HC11 set of
instructions. These directives tell the assembler, not
the 68HC11, to do some action.

Control Directives:
ORG tells the code where to start in memory
NAM should be the first line in a source program;
it gives a name to the program
Data Directives:
FCB Form Constant Byte
FDB Form Double Byte
FCC Form Constant Character
EQU EQUal
RMB Reserve Memory Byte

Flowchart Symbols

Example
Write a program to add the decimal numbers:
1, 5, 9, 13, 17 and 21.
Assume that the numbers are stored in memory locations
C100 C105

Flow Chart

Algorithm

Initialize COUNT
Initialize Pointer
LOAD M(Pointer)
Again: ADD M(Pointer+1)
Dec COUNT
Test if COUNT=Zero
Not? Inc Memory Pointer
Branch to Again
Yes? Finish

Program Documentation
It is very important that every program that is written in
Assembly language be very well documented in order to
make the program understandable to other people an to
the programmer himself.
Written description of how the program works
Flowcharts
Comments

Assembly Code

LDAB #$6
LDAX #C100
LDAA 0,X
Next INX
ADDA 0,X
DECB
BNE
Next
SWI

; initialize counter
; initialize pointer
; load first data
; increment pointer
; add next data
; decrement counter
; check if finished

Jumps and Branches


Program Loops
A loop is a sequence of instructions that will be executed
several times as long as a certain condition is maintained,
or not reached.
The typical structure for a loop is as follows:
Initialize value for ending condition (it could be a logic
function, a counter, an address, a value, etc)
Beginning of the loop (Assign a label to identify the
starting of the loop)
Loop body (set of instructions to be executed
continually)
Actualize value for ending condition (if needed)
Test ending condition
Branch

Branching Instructions
A branch or jump is a break in the normal sequence of
execution of a program.
Typically the instructions of a program are executed
sequentially, the next instruction in the program is executed
after the previous one has been executed. When a program
is been executed, the PC is incremented so that it points to
location in memory of the next instruction in the program to
be executed. However, a branch instruction makes the PC
to be loaded with a new memory address that is not
contiguous to the instruction that was previously executed in
the program.

Types of Branching Instructions:


Unconditional Branch
Conditional Branch

Unconditional Branch:
When the Microcontroller arrives to the branch
instruction, it jumps to the new branch instruction, it
jumps to the new location indicated by the
instruction and continues normal execution of the
program from the new location.

Sequence and Control of Program Execution

Conditional Branch:

When the Microcontroller arrives to the conditional branch


instruction, it test if the branching condition is true and
jumps to the new location indicated by the instruction and
continues normal execution of the program from the new
location.
If the branching condition is false, then the program
continues execution in the normal sequence.

Sequence and Control of Program Execution

Example
Write a program to generate a long chain of numbers that
follow the sequence:
1, 5, 9, 13, . , 20,001
Notice that the next number on the sequence is given by:
New n= Old n+ 4
Variables
N = New number of the sequence to be added
L = counter
The values of N and L should follow the sequences:
N: 1 5 9 13 17 20,001
L : 1 2 3 4 5 5,001

Flow Chart

Variables in Memory
Assume that memory locations $1000 and $1001 are
used to store N (16 bit number), and that memory
locations $1002 and $1003 are used to store L (16 bit
number)
The program code to implement the flow chart is as
follows:

; Initialization Process
Zero

EQU

Four

EQU

ORG

$1000

; origin for data in memory

FDB

; two locations to store sequence number

FDB

5001

; two locations to be used as a counter

ORG

$2000

; origin for program in memory

LDX

; read counter

LDD

; read old value of N

ADDD

#Four

;N=N+4

STD

; store the new value of N

LOOP

DEX
BNE
SWI

; decrement counter by one


LOOP

; repeat until counter zero


; end program

S-ar putea să vă placă și