Professional Documents
Culture Documents
What is a microcontroller?
•A processor
•Usually not cutting edge
•Dependable
•All major bugs well known
•Predictable
•Critical for real-time processing
•On-chip peripherals and memory
•Parallel and serial digital I/O
•Analog I/O
•Counters and timers
•Internal ROM and/or EPROM
HC11 Architecture
CMPE12c 10 Gabriel Hugh Elkaim
M8601 CPU Core
• 8-bit
• CISC
• Accumulator-based
• Results wind up in a 8-bit accumulator A or B
• 16-bit results go to accumulator AB, called D
• Two index registers for addressing memory or for
counting - X and Y
• Dedicated stack pointer
• Push and Pop instructions use this – grows toward
smaller memory addresses like in MAL
• Program Counter
• Condition Codes
CMPE12c 11 Gabriel Hugh Elkaim
M8601 CPU Core
Condition Codes
C Carry/Borrow
V Overflow
Z Zero
N Negative
H Half-Carry
Configuration Registers
I Interrupt Mask
X XIRQ mask
S Disable STOP instructions
Immediate addressing
.sect .text
SUBD var // Subtract [var] from D
SUBD 0x4000 // Subtract [var] from D
CMPE12c 20 Gabriel Hugh Elkaim
HC11 Addressing Modes
Indexed addressing
Inherent addressing
Relative addressing
This group of
instructions supports
arithmetic operations
on a variety of
operands; 8- and 16-bit
operations are
supported directly and
can easily
be extended to support
multiple-word
operands. Twos-
complement
(signed) and binary
(unsigned) operations
are supported directly.
Compare instructions
perform a subtract
within the CPU to
update the condition
code bits without
altering either
operand. Although
test instructions are
provided, they are
seldom needed since
almost all
other operations
automatically update
the condition code
bits.
One multiply and two divide instructions are provided. The 8-bit by 8-bit
multiply produces a 16-bit result. The integer divide (IDIV) performs a
16-bit by 16-bit divide, producing a 16-bit result and a 16-bit remainder.
The fractional divide (FDIV) divides a 16-bit numerator by a larger 16-bit
denominator, producing a 16-bit result (a binary weighted fraction
between 0 and 0.99998) and a 16-bit remainder.
1. Branches
2. Jumps
3. Subroutine calls and returns
4. Interrupt handling
5. Miscellaneous
“C” Addition
c = x + y;
HC11 Assembly
// Integer variables // Character variables
ldd x ldab x
addd y addb y
std c stab c
“C” Multiplication
// c = short variable
// a, b = char variables
c = a * b;
HC11 Assembly
ldaa a
ldab b
mul
std c
cmpa #10
if(a > 10) ble endif
y++; iny
endif:
bra while
endwhile:
CMPE12c 50 Gabriel Hugh Elkaim
“C” Conversions
ldd foo
cpd #7
bgt do
CMPE12c 52 Gabriel Hugh Elkaim
HC11 Example
ldx #0 xgdx
ldab #0 addd 0,y
while: xgdx
cmpb #18
bgt endwhile incb
incb
ldy #array bra while
aby endwhile:
/***********************************************************
* Program 1.
* A simple program to introduce the 68HC11 environment
***********************************************************/
.sect .data
// (continued…)
/*************************************************************
* Your program starts where indicated by the label “main”. After startup
* Code in v2_18g3.asm is done, it jumps to this label and continues running.
**************************************************************/
.sect .text
main:
ldx #SIGNON
jsr OUTSTRING