DOC PREVIEW
NMT EE 308 - 68HC12 Cycles

This preview shows page 1-2-3-4-5-6 out of 17 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 200668HC12 Cycles• Dragon12-Plus board uses a on 48 MHz clock– The on-board oscillator runs at 8 MHz– An internal phase-locked loop multiplies this by 6 to get 48 MHz• A processor cycle takes 2 clock cycles – E clock is 24 MHz• Each processor cycle takes 41.7 ns (1/24 µs) to execute• An instruction takes from 1 to 12 processor cycles to execute• You can determine how many cycles an instruction takes by looking up the CPU cyclesfor that instruction in the S12CPUV2 Reference Manual.– For example, LDAA using the IMM addressing mode shows one CPU cycle (of typeP).– LDAA using the EXT addressing mode shows three CPU cycles (of type rPO).– Section 6.6 of the S12CPUV2 Reference Manual explains what the HCS12 is doingduring each of the different types of CPU cycles.000 org $2000 ; Inst Mode Cycles2000 C6 0A ldab #10 ; LDAB (IMM) 12002 87 loop: clra ; CLRA (INH) 12003 04 31 FC dbne b,loop ; DBNE (REL) 32006 3F swi ; SWI 9The program executes the ldab #10 instruction once (which takes one cycle). It then goesthrough loop 10 times (which has two instructions, on with one cycle and one with threecycles), and finishes with the swi instruction (which takes 9 cycles).Total number of cycles:1 + 10 × (1 + 3) + 9 = 5050 cycles = 50 × 41.7 ns/cycle = 2.08 µs1EE 308 Spring 2006Core User Guide — S12CPU15UG V1.2408Operation (M) ⇒ Borimm ⇒ BLoads B with either the value in M or an immediate value.CCREffectsCode andCPUCyclesLDABLoad BLDABS X H I N Z V C– – – – ∆ ∆ 0 –N: Set if MSB of result is set; cleared otherwiseZ: Set if result is $00; cleared otherwiseV: ClearedSource FormAddressModeMachineCode (Hex)CPU CyclesLDAB #opr8iLDABopr8aLDABopr16aLDABoprx0_xysppcLDABoprx9,xysppcLDABoprx16,xysppcLDAB [D,xysppc]LDAB [oprx16,xysppc]IMMDIREXTIDXIDX1IDX2[D,IDX][IDX2]C6 iiD6 ddF6 hh llE6 xbE6 xb ffE6 xb ee ffE6 xbE6 xb ee ffPrPfrPOrPfrPOfrPPfIfrPffIPrPf2EE 308 Spring 2006HC12 Assembly Language ProgrammingProgramming ModelAddressing ModesAssembler DirectivesHC12 InstructionsFlow Charts3EE 308 Spring 2006Assembler Directives• In order to write an assembly language program it is necessary to use assembler direc-tives.• These are not instructions which the HC12 executes but are directives to the assemblerprogram about such things as where to put code and data into memory.• All of the assembler directives can be found in as12.html on the EE 308 home page.• We will use only a few of these directives. (Note: In the following table, [] means anoptional argument.) Here are the ones we will need:Directive Name Description Exampleequ Give a value to a symbol len: equ 100org Set starting value of location counter org $1000where code or data will godc.b Allocate and initialize storage var: dc.b 2,18db for 8-bit variables.fcb Place the bytes in s uccessive memory locationsdc.w Allocate and initialize storage var: dc.w $ABCDdw for 16-bit variables.fdb Place the bytes in successive memory locationsds.b Allocate specified number of table: ds.w 10ds 8-bit storage spaces.rmbds.w Allocate specified number of table2: ds.w 50rmw 16-bit storage spaces.fcc Encodes a string string: fcc "Hello"of ASCII characters. The firstcharacteris the delimiter. Thestring terminates at the nextoccurrence of the delimiterfill Fill memory with a given value init_data: fill 100,0The first value is the number of bytes to fill.The second number is the value to putinto memory4EE 308 Spring 2006Using labels in assembly programsA label is defined by a name followed by a colon as the first thing on a line. When the labelis referred to in the program, it has the numerical value of the location counter when thelabel was defined.Here is a code fragment using labels and the assembler directives dc and ds:org $2000table1: dc.b $23,$17,$f2,$a3,$56table2: ds.b 5var: dc.w $43afThe as12 assembler produces a listing file (.lst) and a symbol file (.sym). Here is the listingfile from the assembler:as12, an absolute assembler for Motorola MCU’s, version 1.2e2000 org $20002000 23 17 f2 a3 56 table1: dc.b $23,$17,$f2,$a3,$562005 table2: ds.b 5200A 43 af var: dc.w $43af5EE 308 Spring 2006And here is the symbol file:table1 2000table2 2005var 200ANote that table1 is a name with the value of $2000, the value of the lo cation counter definedin the org directive. Five bytes of data are defined by the dc.b directive, so the locationcounter is increased from $2000 to $2005. table2 is a name with the value of $2005. Fivebytes of data are set aside for table2 by the ds.b 5 directive. The as12 assembler initializedthese five bytes of data to all zeros. var is a name with the value of $200a, the first locationafter table2.6EE 308 Spring 2006HC12 Assembly Language ProgrammingProgramming ModelAddressing ModesAssembler DirectivesHC12 InstructionsFlow Charts7EE 308 Spring 20061. Data Transfer and Manipulation Instructions — instructions which move and manipu-late data (S12CPUV2 Reference Manual, Sections 5.3, 5.4, and 5.5).• Load and Store — load copy of memory conte nts into a register; store copy ofregister contents into memory.LDAA $2000 ; Copy contents of addr $2000 into ASTD 0,X ; Copy contents of D to addrs X and X+1• Transfer — copy contents of one register to another.TBA ; Copy B to ATFR X,Y ; Copy X to Y• Exhange — exchange contents of two registers.XGDX ; Exchange contents of D and XEXG A,B ; Exchange contents of A and B• Move — copy contents of one memory location to another.MOVB $2000,$20A0 ; Copy byte at $2000 to $20A0MOVW 2,X+,2,Y+ ; Copy two bytes from address held; in X to address held in Y; Add 2 to X and Y2. Arithmetic Instructions — addition, subtraction, multiplication, divison (S12CPUV2Reference Manual, Sections 5.6, 5.8 and 5.12).ABA ; Add B to A; results in ASUBD $20A1 ; Subtract contents of $20A1 from DINX ; Increment X by 1MUL ; Multiply A by B; results in D3. Logic and Bit Instructions — perform logical operations (S12CPUV2 ReferenceManual, Sections 5.9, 5.10, 5.11, 5.13 and 5.14).• Logic InstructionsANDA $2000 ; Logical AND of A with contents of $2000EORB 2,X ; Exclusive OR B with contents of address (X+2)• Clear, Complement and Negate InstructionsNEG -2,X ; Negate (2’s comp) contents of address (X-2)CLRA ; Clear Acc A8EE 308 Spring 2006• Bit manipulate and test instructions — work with one bit of a register or memory.BITA #$08 ; Check to see if Bit 3 of A is setBSET $0002,#$18 ; Set bits 3 and 4 of address $002• Shift and rotate instructionsLSLA ; Logical


View Full Document

NMT EE 308 - 68HC12 Cycles

Documents in this Course
Load more
Download 68HC12 Cycles
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view 68HC12 Cycles and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view 68HC12 Cycles 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?