1
Motorola HC-11 Motorola HC-11
Microcontrollers and Embedded SystemsMicrocontrollers and Embedded Systems
2
• A microprocessorA microprocessor– Usually not cutting edge– Dependable
• All major bugs well knownAll major bugs well known– Predictable
• Critical for real-time processingCritical for real-time processing
• On-chip peripherals and memoryOn-chip peripherals and memory– Parallel and serial digital I/O– Analog I/O– Counters and timers
• Internal ROM and/or EPROMInternal ROM and/or EPROM
What is a microcontroller?What is a microcontroller?
3
What are microcontrollers used in?What are microcontrollers used in?
• WatchesWatches• MicrowavesMicrowaves• Stereo ReceiversStereo Receivers
Some products that you might know:Some products that you might know:
• NASA’s Sojourner Rover – 8-bit Intel 80C85NASA’s Sojourner Rover – 8-bit Intel 80C85• Palm Vx handheld – 32-bit Motorola Dragonball EZPalm Vx handheld – 32-bit Motorola Dragonball EZ• Sonicare toothbrush – 8-bit Zilog Z8Sonicare toothbrush – 8-bit Zilog Z8• The Vendo V-MAX 720 Soda Machine – Motorola HC11The Vendo V-MAX 720 Soda Machine – Motorola HC11• Miele dishwasher – 8-bit Motorola 68HC05Miele dishwasher – 8-bit Motorola 68HC05• Hunter 44550 Programmable Thermostat – (4-bit cpu)Hunter 44550 Programmable Thermostat – (4-bit cpu)
Microcontrollers Microcontrollers
• ATMsATMs• PDA’s, MP3 playersPDA’s, MP3 players• AutomobilesAutomobiles
4
Microcontrollers
Microcontroller unit sales are 15x higher than microprocessors. … and are MUCH, MUCH cheaper.
5
Microcontrollers
Microcontroller MarketsMicrocontroller Markets
• MicrocontrollerMicrocontrollers are a large s are a large marketmarket
• 8-bit 8-bit controllers are controllers are the largest, the largest, but not but not growing the growing the fastest.fastest.
6
Microcontrollers Microcontrollers
• 8-bit microcontroller growth rate for 2003 8-bit microcontroller growth rate for 2003 is at 9.42%.is at 9.42%.
• Microcontroller growth rate in general is Microcontroller growth rate in general is 11.5%.11.5%.
• 8-bit controllers loosing market share in 8-bit controllers loosing market share in 2003. Was 62.36% in 1998 down to 2003. Was 62.36% in 1998 down to 56.76% in 2003.56.76% in 2003.
Source: Cahners In-Stat GroupSource: Cahners In-Stat Group
7
• 16- and 32-bit and higher are on the 16- and 32-bit and higher are on the rise. They will double their unit market rise. They will double their unit market share from 15.11% in 1998 up to share from 15.11% in 1998 up to 31.56% in 2003, decreasing 4-bit and 8-31.56% in 2003, decreasing 4-bit and 8-bit devices.bit devices.
• But, in 2003, the 8-bit microcontrollers But, in 2003, the 8-bit microcontrollers will outnumber the higher bit units by will outnumber the higher bit units by almost 80% in the market place.almost 80% in the market place.
Source: Cahners In-Stat GroupSource: Cahners In-Stat Group
Microcontrollers Microcontrollers
8
Microcontrollers Microcontrollers
So what languages are they being So what languages are they being programmed in?programmed in?
LanguageLanguage ‘‘98-’9998-’99 ‘‘99-’0099-’00
AssemblyAssembly ~ 21%~ 21% ~ 10%~ 10%
CC ~ 69%~ 69% ~ 80%~ 80%
C++C++ ~ 5%~ 5% ~ 6%~ 6%
JavaJava ~ 1 %~ 1 % ~ 2%~ 2%
OtherOther ~ 3 %~ 3 % ~ 2%~ 2%
Source: TRON Association Survey 1998/99 & 1999/2000Source: TRON Association Survey 1998/99 & 1999/2000
9
Motorola M68HC11Motorola M68HC11
• M6801 CPU coreM6801 CPU core
• ROM (8KB), EEPROM (512B), RAM (256B)ROM (8KB), EEPROM (512B), RAM (256B)– Counter/Timer system– A/D converter
• D/A in kitD/A in kit
• Parallel I/OParallel I/O
• Serial I/O (SPI and SCI)Serial I/O (SPI and SCI)
• Expansion busExpansion bus– To add more memory
11
• 8-bit8-bit
• CISCCISC
• Accumulator-basedAccumulator-based
• Results wind up in a 8-bit accumulator A or BResults wind up in a 8-bit accumulator A or B
• 16-bit results go to accumulator AB, called D16-bit results go to accumulator AB, called D
• Two index registers for addressing memory or for counting - X Two index registers for addressing memory or for counting - X and Yand Y
• Dedicated stack pointerDedicated stack pointer
• Push and Pop instructions use this – grows toward smaller Push and Pop instructions use this – grows toward smaller memory addresses like in LC-3memory addresses like in LC-3
• Program CounterProgram Counter
• Condition CodesCondition Codes
M8601 CPU Core M8601 CPU Core
12
Check out the lab manualCheck out the lab manual
• It is online on the class website It is online on the class website
• Contains a section on the HC11Contains a section on the HC11
• It is a great referenceIt is a great reference
Also get the programmer reference Also get the programmer reference guide, free at BELS (basement of BE)guide, free at BELS (basement of BE)
15
• More present then in LC-3More present then in LC-3• Single-bit flags set appropriately for most Single-bit flags set appropriately for most instructionsinstructions (several instructions do not, including push and (several instructions do not, including push and pop)pop)
CC Carry/BorrowCarry/BorrowVV OverflowOverflowZZ ZeroZeroNN NegativeNegativeHH Half-CarryHalf-Carry
HC11 Microcontroller HC11 Microcontroller
Condition CodesCondition Codes
16
HC11 codeHC11 code What it doesWhat it does
cmpa #4cmpa #4 Subtract AccA - 4, set CCRSubtract AccA - 4, set CCR
bge mylabelbge mylabel Branch ifBranch if
(CCR[Z]=1 OR CCR[N]=0)(CCR[Z]=1 OR CCR[N]=0)
Example of how condition codes are Example of how condition codes are usedused
HC11 Microcontroller HC11 Microcontroller
17
HC11 Assembly SyntaxHC11 Assembly Syntax• Have separate sections for data Have separate sections for data
declarations and for instructionsdeclarations and for instructions– Use “.sect .data” for data sections– Use “.sect .text” for instructions sections.
• Have more data typesHave more data types– “.space” for array declarations– “.byte” declares just a byte– “.word” declares 16-bits also– “.asciz” declares a string of characters– “.ascii” declares a string, no NULL terminator
• Comments use a “C++” style “//”Comments use a “C++” style “//”
18
Data Declaration Data Declaration ExamplesExamples
.sect .data .sect .data
myvar: .wordmyvar: .word 0x1000 // init a word0x1000 // init a word
myarray: .space 20 // 20 entriesmyarray: .space 20 // 20 entries
mychar: .byte ‘a’ // a charactermychar: .byte ‘a’ // a character
mybyte: .byte 23 // DEC integermybyte: .byte 23 // DEC integer
myhi: .asciz “Hi” // a stringmyhi: .asciz “Hi” // a stringmyhi2: .ascii “Hi” // a stringmyhi2: .ascii “Hi” // a string
.sect .text.sect .text
// Instructions would start here.// Instructions would start here.
// Can have many .text and .data sections.// Can have many .text and .data sections.
19
Bits set by the user to tell the processor how to doBits set by the user to tell the processor how to dothingsthings
II Interrupt MaskInterrupt MaskXX XIRQ maskXIRQ maskSS Disable STOP instructionsDisable STOP instructions
HC11 Microcontroller HC11 Microcontroller
Configuration RegistersConfiguration Registers
20
Return to Addressing ModesReturn to Addressing Modes
Addressing Modes:Addressing Modes:
LC-3 has:LC-3 has:• PC-RelativePC-Relative• Base DisplacementBase Displacement• IndirectIndirect
HC11 has many: HC11 has many: • Check opcode listings to see what modes workCheck opcode listings to see what modes workwith what instructionswith what instructions• Also check what condition codes are setAlso check what condition codes are set
21
HC11 Addressing ModesHC11 Addressing Modes
•Immediate (IMM)Immediate (IMM)
•Extended (EXT)Extended (EXT)
•Direct (DIR)Direct (DIR)
•Indexed (INDX and INDY)Indexed (INDX and INDY)
•Inherent (INH)Inherent (INH)
•Relative (REL)Relative (REL)
Supports these addressing modes:Supports these addressing modes:
22
Immediate addressingImmediate addressing
•1 or 2 byte immediate depending on register involved1 or 2 byte immediate depending on register involved(LDAA vs. LDD)(LDAA vs. LDD)•ALWAYSALWAYS include a # include a #•Several formats for different bases -- C-style Several formats for different bases -- C-style constants instead of what is in the HC11 constants instead of what is in the HC11 manual (don’t use !,$,@,%)manual (don’t use !,$,@,%)
•Decimal:Decimal: LDAA #245LDAA #245•Hexadecimal:Hexadecimal: LDAA #0x61LDAA #0x61•Octal: Octal: LDAA #041LDAA #041•Binary:Binary: LDAA #0b11000011LDAA #0b11000011•ASCII:ASCII: LDAA #’a’LDAA #’a’
HC11 Addressing ModesHC11 Addressing Modes
23
Extended and Direct addressingExtended and Direct addressing
•Access an absolute memory locationAccess an absolute memory location•Essentially the same mode, but with 8-bit (direct)Essentially the same mode, but with 8-bit (direct)or 16-bit (enhanced or extended) addressesor 16-bit (enhanced or extended) addresses•The assembler will decide on which to use basedThe assembler will decide on which to use basedon how many bits are neededon how many bits are needed•ExampleExample
// Your data starts at address 0x4000:// Your data starts at address 0x4000:.sect .data.sect .datavar:var: .word.word 0x10000x1000 // Allocate/initialize a word // Allocate/initialize a word
// Note: a word is 16 bits! // Note: a word is 16 bits!
.sect .text.sect .textSUBDSUBD varvar // Subtract [var] from D// Subtract [var] from DSUBDSUBD 0x40000x4000 // Subtract [var] from D// Subtract [var] from D
HC11 Addressing ModesHC11 Addressing Modes
24
Indexed addressingIndexed addressing
•Uses index register X or YUses index register X or Y•Similar to LC-3 “LDR R0, R2, #3Similar to LC-3 “LDR R0, R2, #3””
•But can access memory and use it all at once!!But can access memory and use it all at once!!•Example Example
#define#define mydefmydef 44 // c preprocessor used// c preprocessor usedldxldx #var#var // Like LC-3 load address// Like LC-3 load addressadddaddd 0,X0,X // add contents of M[0+X] to D// add contents of M[0+X] to D
// (Note “addd X” doesn’t work)// (Note “addd X” doesn’t work)adddaddd 2,X2,X // add contents of M[2+X] to D// add contents of M[2+X] to Dadddaddd mydef*2, Xmydef*2, X // add contents of M[8+X] to D// add contents of M[8+X] to D
HC11 Addressing ModesHC11 Addressing Modes
25
Inherent addressingInherent addressing
•Opcode fully specifies operation; no addressingOpcode fully specifies operation; no addressing•Examples:Examples:
INCBINCB increment accumulator B increment accumulator BASLAASLA Arithmetic Shift Left accumulator A Arithmetic Shift Left accumulator APSHYPSHY Push index register Y onto stack Push index register Y onto stack
HC11 Addressing ModesHC11 Addressing Modes
26
Relative addressingRelative addressing
• Used for branches by the assemblerUsed for branches by the assembler• Offsets from –128 to +128 bytesOffsets from –128 to +128 bytes• Use jumps for longer branchesUse jumps for longer branches
HC11 Addressing ModesHC11 Addressing Modes
27
HC11 Address Modes HC11 Address Modes ReviewReview
ldab #0ldab #0 // loads the number 0 into b// loads the number 0 into b
ldaa fooldaa foo // loads the contents of byte// loads the contents of byte// variable foo into “a” acc.// variable foo into “a” acc.
ldy #fooldy #foo // loads the address of foo into y// loads the address of foo into y
ldab 0, xldab 0, x // loads the byte at address x+0// loads the byte at address x+0// into “b” acc.// into “b” acc.
ldx 0ldx 0 // loads whatever is at memory// loads whatever is at memory// address 0 into “x” index. // address 0 into “x” index. // You don't want this in 12c ever. // You don't want this in 12c ever.
28
Motorola 68HC11 Motorola 68HC11 InstructionsInstructions
• HC11 Instructions have variable lengthsHC11 Instructions have variable lengths– not like LC-3
• Careful coding can keep applications small and Careful coding can keep applications small and able to fit in the EPROMable to fit in the EPROM
• We don’t have to worry about this since we’re We don’t have to worry about this since we’re using Expansion Modeusing Expansion Mode– there is extra memory in the microkits.
• The opcode is always 1 byteThe opcode is always 1 byte
• An additional 0-3 bytes specify the data to An additional 0-3 bytes specify the data to work withwork with
29
Motorola 68HC11 Instruction Motorola 68HC11 Instruction SetSet
• Accumulator and Memory Accumulator and Memory InstructionsInstructions
• Stack and Index Register Stack and Index Register InstructionsInstructions
• Condition Code Register Condition Code Register InstructionsInstructions
• Program Control InstructionsProgram Control Instructions
30
Accumulator and Memory Accumulator and Memory InstructionsInstructions
Can be broken up into these 6 general Can be broken up into these 6 general types:types:
1.1. Loads, stores, and transfersLoads, stores, and transfers
2.2. Arithmetic operationsArithmetic operations
3.3. Multiply and divideMultiply and divide
4.4. Logical operationsLogical operations
5.5. Data testing and bit manipulationData testing and bit manipulation
6.6. Shifts and rotatesShifts and rotates
HC11 InstructionsHC11 Instructions
31
HC11 HC11 InstructionsInstructions
Almost all MCU Almost all MCU activities involve activities involve transferring data transferring data from memories orfrom memories orperipherals into peripherals into the CPU or the CPU or transferring transferring results from the results from the CPU into memory CPU into memory or I/O devices.or I/O devices.
32
HC11 HC11 InstructionsInstructions
This group of This group of instructions instructions supports arithmetic supports arithmetic operations on a operations on a variety ofvariety ofoperands; 8- and operands; 8- and 16-bit operations 16-bit operations are supported are supported directly and can directly and can easily be extended easily be extended to support multiple-to support multiple-word operands. word operands. Twos-complement Twos-complement (signed) and binary (signed) and binary (unsigned) (unsigned) operations are operations are supported directly.supported directly.
33
HC11 InstructionsHC11 Instructions
Compare Compare instructions instructions perform a subtract perform a subtract within the CPU towithin the CPU toupdate the update the condition code bits condition code bits without altering without altering either operand. either operand. AlthoughAlthoughtest instructions test instructions are provided, they are provided, they are seldom are seldom needed since needed since almost all other almost all other operations operations automatically automatically update the update the condition code condition code bits.bits.
34
HC11 InstructionsHC11 Instructions
One multiply and two divide instructions are provided. The 8-bit by 8-bitOne multiply and two divide instructions are provided. The 8-bit by 8-bitmultiply produces a 16-bit result. The integer divide (IDIV) performs amultiply produces a 16-bit result. The integer divide (IDIV) performs a16-bit by 16-bit divide, producing a 16-bit result and a 16-bit remainder.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-bitThe fractional divide (FDIV) divides a 16-bit numerator by a larger 16-bitdenominator, producing a 16-bit result (a binary weighted fractiondenominator, producing a 16-bit result (a binary weighted fractionbetween 0 and 0.99998) and a 16-bit remainder.between 0 and 0.99998) and a 16-bit remainder.
35
HC11 Instructions
This group of instructions is used to perform the Boolean logicaloperations AND, inclusive OR, exclusive OR, and one’s complement.
36
HC11 HC11 InstructionsInstructions
This group of instructions is used to operate on operands as small as This group of instructions is used to operate on operands as small as aasingle bit, but these instructions can also operate on any single bit, but these instructions can also operate on any combination ofcombination ofbits within any 8-bit location in the 64-Kbyte memory space. bits within any 8-bit location in the 64-Kbyte memory space.
37
HC11 HC11 InstructionsInstructions
All the shift and All the shift and rotate functions in rotate functions in the M68HC11 CPU the M68HC11 CPU involve the carry bit involve the carry bit in the CCR in in the CCR in addition to the 8- or addition to the 8- or 16-bit operand in 16-bit operand in the instruction, the instruction, which permits easy which permits easy extension to extension to multiple-word multiple-word operands.operands.
38
Stack and Index Register Stack and Index Register InstructionsInstructions
HC11 InstructionsHC11 Instructions
39
HC11 InstructionsHC11 Instructions
This table summarizes This table summarizes the instructions the instructions available for the 16-bit available for the 16-bit index registers (X and index registers (X and Y) and the 16-bit stack Y) and the 16-bit stack pointer.pointer.
40
HC11 System StackHC11 System Stack
• The HC11 has a stack set up for usThe HC11 has a stack set up for us
• Memory is “byte” addressableMemory is “byte” addressable
Example:Example:
PSHA // pushes accumulator A onto stackPSHA // pushes accumulator A onto stack
// SP = SP – 1 since a byte size// SP = SP – 1 since a byte size
PSHY // pushes index register Y onto stackPSHY // pushes index register Y onto stack
// SP = SP – 2 since a word size// SP = SP – 2 since a word size
PULA // Pops off a byte from the stack into APULA // Pops off a byte from the stack into A
// SP = SP + 1// SP = SP + 1
PULY // Pops off a word from the stack into YPULY // Pops off a word from the stack into Y
// SP = SP + 2 // SP = SP + 2
41
HC11 InstructionsHC11 Instructions
Condition Code Register Condition Code Register InstructionsInstructions
These instructions allow a programmer to manipulate bits of the These instructions allow a programmer to manipulate bits of the CCR.CCR.
42
Program Control Program Control InstructionsInstructions
1. Branches1. Branches2. Jumps2. Jumps3. Subroutine calls and 3. Subroutine calls and returnsreturns4. Interrupt handling4. Interrupt handling5. Miscellaneous5. Miscellaneous
HC11 HC11 InstructionsInstructions
43
These instructions These instructions allow the CPU to make allow the CPU to make decisions based on the decisions based on the contents of the contents of the condition code bits. All condition code bits. All decision blocks in a decision blocks in a flow chart would flow chart would correspond to one of correspond to one of the conditional branch the conditional branch instructions instructions summarized heresummarized here
HC11 InstructionsHC11 Instructions
44
HC11 HC11 InstructionsInstructions
The jump instruction allows control to be passed The jump instruction allows control to be passed to any address in the 64-Kbyte memory map.to any address in the 64-Kbyte memory map.
45
HC11 InstructionsHC11 Instructions
These instructions provide an easy way to divide a programming taskThese instructions provide an easy way to divide a programming taskinto manageable blocks called subroutines. The CPU automates theinto manageable blocks called subroutines. The CPU automates theprocess of remembering the address in the main program whereprocess of remembering the address in the main program whereprocessing should resume after the subroutine is finished. This addressprocessing should resume after the subroutine is finished. This addressis automatically pushed onto the stack when the subroutine is called is automatically pushed onto the stack when the subroutine is called andandis pulled off the stack during the RTS instruction that ends theis pulled off the stack during the RTS instruction that ends thesubroutinesubroutine
46
This group of instructions is related to interrupt operations, we This group of instructions is related to interrupt operations, we will get to there use later.will get to there use later.
HC11 InstructionsHC11 Instructions
47
NOP is a do nothing instruction, just wastes an instruction cycle. NOP is a do nothing instruction, just wastes an instruction cycle. STOP is used to put the CPU into a low power mode. TEST is a STOP is used to put the CPU into a low power mode. TEST is a reserved instruction only used at the factory when making the chips.reserved instruction only used at the factory when making the chips.
HC11 InstructionsHC11 Instructions
48
““C” ConversionsC” Conversions
““C” AdditionC” Addition
c = x + yc = x + y
// Character variables// Character variablesldab xldab xaddb yaddb ystab cstab c
HC11 AssemblyHC11 Assembly
// Integer variables // Integer variables ldd xldd xaddd yaddd ystd cstd c
49
““C” C” ConversionsConversions
HC11 AssemblyHC11 Assembly
// c goes in double acc// c goes in double acc// x, y are the index // x, y are the index regsregs
pshxpshxxgdxxgdxpshypshytsxtsxaddd 0,xaddd 0,xpulypulypulxpulx
HC11 AssemblyHC11 Assembly
// Using character registers// Using character registers// acc a = x, acc b = y.// acc a = x, acc b = y.
abaaba
““C” Addition C” Addition c = x + yc = x + y
““C” Addition C” Addition x = x + yx = x + y
50
“C” Multiplication
// c = short variable // a, b = char variablesc = a * b
HC11 Assembly
ldaa aldab bmulstd c
“C” Conversions
52
““C” ConversionsC” Conversions
““C” if/else C” if/else statement:statement:
char a; short y;char a; short y;
if(a > 10) if(a > 10) y++; y++;
else else y--;y--;
““HC11” HC11” Assembly:Assembly:
cmpa #10cmpa #10bgt ifbgt ifdeydeybra endifbra endif
if:if: inyinyendif:endif:
53
““C” ConversionsC” Conversions
““C” if/else C” if/else statement:statement:
char foo; char foo; short qux;short qux;
if(foo > 10) if(foo > 10) qux++; qux++;
else else qux--;qux--;
““HC11” HC11” Assembly:Assembly:
ldaa fooldaa foocmpa #10cmpa #10bgt ifbgt ifldy quxldy quxdeydeysty quxsty quxbra endifbra endif
if:if: ldy quxldy quxinyinysty quxsty qux
endif:endif:
54
““C” ConversionsC” Conversions
““C” while C” while statement:statement:
char a, b;char a, b;
while(a > 20) while(a > 20) {{a--; a--; b *= 3;b *= 3;}}
““HC11” Assembly:HC11” Assembly:
while:while:cmpa #20cmpa #20ble endwhileble endwhiledecadeca
pshapshaldaa #3ldaa #3mulmulpulapula
bra whilebra whileendwhile:endwhile:
55
““C” if/else C” if/else statement:statement:
char foo; char foo; short qux;short qux;
if(foo > 10) if(foo > 10) qux++; qux++;
else else qux--;qux--;
““HC11” HC11” Assembly:Assembly:
ldaa fooldaa foocmpa #10cmpa #10bgt ifbgt ifldy quxldy quxinyinysty quxsty quxbra endifbra endif
if:if: ldy quxldy quxinyinysty quxsty qux
endif:endif:
““C” ConversionsC” Conversions
56
““C” do/while C” do/while statement:statement:
int foo, bar, qux;int foo, bar, qux;
do {do {foo -= 3; foo -= 3; bar += qux;bar += qux;} }
while (foo > 7)while (foo > 7)
““HC11” HC11” Assembly:Assembly:
do:do:ldd fooldd foosubd #3subd #3std foostd foo
ldd barldd baraddd quxaddd quxstd barstd bar
ldd fooldd foocpd #7cpd #7bgt dobgt do
““C” ConversionsC” Conversions
57
Summing the first 10 elements of an Summing the first 10 elements of an integer array, result in index register X:integer array, result in index register X:
array: .space 20array: .space 20
ldx #0ldx #0ldab #0ldab #0
while:while:cmpb #18cmpb #18bgt endwhilebgt endwhile
ldy #arrayldy #arrayabyaby
xgdxxgdxaddd 0,yaddd 0,yxgdxxgdx
incbincbincbincbbra whilebra while
endwhile:endwhile:
HC11 ExampleHC11 Example
58
HC11 ExampleHC11 Example
/***********************************************************/*********************************************************** ** Program 1.Program 1. * * A simple program to introduce the 68HC11 environmentA simple program to introduce the 68HC11 environment ***********************************************************/ ***********************************************************/ #include <v2_18g3.asm> // sets stuff up for you, especially I/O#include <v2_18g3.asm> // sets stuff up for you, especially I/O
.sect .data.sect .data
SIGNON:SIGNON: .asciz.asciz “CMPE12C Simulator”“CMPE12C Simulator”PROMPT:PROMPT: .asciz.asciz “>”“>”
// (continued…)// (continued…)
59
HC11 Example ContinuedHC11 Example Continued
/*************************************************************/************************************************************** Your program starts where indicated by the label “main”. After startup * 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.* Code in v2_18g3.asm is done, it jumps to this label and continues running.**************************************************************/**************************************************************/
.sect .text.sect .text
main:main:ldxldx #SIGNON#SIGNONjsrjsr OUTSTRINGOUTSTRING
loop:loop: ldxldx #PROMPT#PROMPT // address of prompt// address of promptjsrjsr OUTSTRINGOUTSTRING // write out to serial communications// write out to serial communications
// interface (to PC)// interface (to PC)jsrjsr GETCHARGETCHAR // get a character from SCI, returns in A// get a character from SCI, returns in Ajsrjsr OUTCHAROUTCHAR // write A to the SCI// write A to the SCIjsrjsr OUTCRLFOUTCRLF // write CR/LF to SCI// write CR/LF to SCIjmpjmp looploop
60
• Design environment:Design environment:– Edit & assemble on CATS machines– > hc11build file.asm
• Download program to the PCDownload program to the PC
• Upload to the microkit using serial cableUpload to the microkit using serial cable
• To use kits at homeTo use kits at home– 9-12V AC adapter– Serial download cable
• Connection to CATS machinesConnection to CATS machines
• Free serial communication software (e.g. TeraTerm)Free serial communication software (e.g. TeraTerm)
HC11 Micro Kit Usage HC11 Micro Kit Usage
61
Micro Kit Usage Micro Kit Usage
Always #include <v2_18g3.asm> as part of your programAlways #include <v2_18g3.asm> as part of your program
• Sets up memory, including stack pointerSets up memory, including stack pointer• Jumps to your “main” labelJumps to your “main” label• Also includes a basic library of I/O routinesAlso includes a basic library of I/O routines• Take a look at it!Take a look at it! http://www.soe.ucsc.edu/classes/cmpe012/Winter05/In the handouts and links page under HC11 StuffIn the handouts and links page under HC11 Stuff
62
Example recursive routine Example recursive routine
Fibonacci on the switches and LEDsFibonacci on the switches and LEDs
/* Input: A. Returns A’th Fibonacci term in accumulator A *//* Input: A. Returns A’th Fibonacci term in accumulator A */fib:fib: cmpacmpa #2#2
bgtbgt fibnot1fibnot1ldaaldaa #1#1 // return 1 if n <= 2// return 1 if n <= 2rtsrts
fibnot1:fibnot1: pshbpshb // caller save protocol// caller save protocoldecadecapshapsha // save n-1// save n-1decadeca // call with n-2// call with n-2jsrjsr fibfibtabtab // transfer F(n-2) to b// transfer F(n-2) to bpulapula // a gets n-1// a gets n-1jsrjsr fibfibabaaba // add accumulators// add accumulatorspulbpulb // restore B// restore Brtsrts
main:main: ldxldx #SWITCHES#SWITCHESldaaldaa 0,X0,X
jsrjsr fibfibldxldx #LEDS#LEDSstaastaa 0,x0,xjmpjmp mainmain
63
• Microcontrollers are great little processors for I/O and data Microcontrollers are great little processors for I/O and data manipulationmanipulation
• The CISC-style programming makes assembly programming easierThe CISC-style programming makes assembly programming easier• Variable instruction length can be a problem forVariable instruction length can be a problem for
– Word-aligned machines– Super-scalar machines– Pipelines
• The RISC philosophy is toThe RISC philosophy is to– Use simple instructions and let the compiler optimize– Use loads and stores to support higher-speed registers
• Neither RISC, its CISC predecessors, nor CISCY RISCY has the definitive Neither RISC, its CISC predecessors, nor CISCY RISCY has the definitive advantageadvantage– Depends on application, architecture, and implementation.
Microcontroller/HC11 Microcontroller/HC11 SummarySummary