DOC PREVIEW
NMT EE 308 - HCS12 Assembly Language Programming

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 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 8 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 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2003Programming ModelAddressing ModesAssembler DirectivesFlow ChartsHCS12 Assembly Language ProgrammingHCS12 Instructions1EE 308 Spring 2003Assembler DirectivesIn order to write an assembly language program it is necessary to use assem-bler directives.These are not instructions which the HCS12 executes but are directives tothe assembler program about such things as where to put code and data intomemory.All of the assembler directives can be found in Pages 46 through 49 of themanual for the evaluation version of the Cosmic Compiler. A PDF version ofthis manual can be found on the EE 308 home page.We will use only a few of these directives. (Note: In the following table, []means an optional 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 gosection Define a new program section CODE: section .textFor example, code or datadc[.size] Allocate and initialize storage var: dc.b 2,18for variables. Size can be b (byte),w (two bytes) or l (4 bytes)If no size is specified, b is usedds[.size] Allocate specified number of table: ds.w 10storage spaces. size is the sameas for dc directive2EE 308 Spring 2003Using labels in assembly programsA label is defined by a name followed by a colon as the first thing on a line. Whenthe label is referred to in the program, it has a numerical value of the locationcounter when the label was defined.Here is a code fragment using labels and the assembler directives dc and ds:DATA: section .data ;The stuff which follows is dataorg $0900table1: dc.b $23,$17,$f2,$a3,$56table2: ds.b 5var: dc.w $43afHere is the listing from the assembler:9 DATA: section .data ;The stuff which follows is data10 0900 org $090011 0900 2317f2a356 table1: dc.b $23,$17,$f2,$a3,$5612 0905 0000000000 table2: ds.b 513 090a 43af var: dc.w $43afAnd here is the map file:Map of demo.h12 from link file demo.lkf - Thu Jan 25 09:56:12 2001table1 00000900table2 00000905var 0000090aNote that, table1 is a name with the value of $0900, the value of the locationcounter defined in the org directive. Five bytes of data are defined by the dc.bdirective, so the location counter is increased from $0900 to $0905. table2 isa name with the value of $0905. Five bytes of data are set aside for table2 bythe ds.b 5 directive. The Cosmic assembler initialized these five bytes of datato all zeros.3EE 308 Spring 2003Programming ModelAddressing ModesAssembler DirectivesFlow ChartsHCS12 Assembly Language ProgrammingHCS12 Instructions4EE 308 Spring 20031. Data Transfer and Manipulation Instructions — instructions which move andmanipulate data (HCS12 VI.5 User Guide).Load and Store — load copy of memory contents into a register; storecopy of register contents into memory.LDAA $0900 ; Copy contents of addr $0900 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 $0900 $09A0 ; Copy byte at $0900 to $09A0MOVW 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.ABA ; Add B to A; result is in ASUBD $09A1 ; Subtract contents of $09A1 from DINX ; Increment X by 1MUL ; Multiply A by B; results in D3. Logic and Bit Instructions — perform logical operations.Logic InstructionsANDA $0900 ; Logical AND of A with contents of $0900NEG -2,X ; Negate (2’ comp) contents of address (X-2)LSLA ; Logical shift left A by 15EE 308 Spring 2003Bit manipulate and test instructions — work with one bit of a register ormemory.BITA #$08 ; Check to see if Bit 3 of A is setBSET $0002,#$18 ; Set bits 3 and 4 of address $00024. Data test instructions — test contents of a register or memory (to see if zero,negative, etc.), or compare contents of a register to memory (to see if biggerthan, etc.)TSTA ; (A)-0 -- set flags accordinglyCPX #$8000 ; (X) - $8000 -- set flags accordingly5. Jump and Branch Instructions — Change flow of program (e.g., goto, it-then-else, switch-case).JMP l1 ; Start executing code at address label l1BEQ l2 ; If Z bit is one, go to label l2DBNE X l3 ; Decrement X; if X not 0 then goto l3BRCLR $1A,#$80 l4 ; If bit 7 of addr $1A is zero, goto l46. Function Call and Interrupt Instructions — initiate or terminate a subroutine;initiate or terminate an interrupt call.Subroutine instructions:JSR sub1 ; Jump to subroutine sub1RTS ; Return from subroutineInterrupt instructionsSWI ; Initiate software interruptRTI ; Return from interrupt6EE 308 Spring 20037. Stacking Instructions — push data onto and pull data off of stack.PSHA ; Push contents of A onto stackPULX ; Pull two top bytes of stack, put into X8. Stop and Wait Instructions — put HCS12 into low power mode.STOP ; Put into lowest power modeWAI ; Put into low power mode until next interrupt9. Instructions we won’t discuss or use — BCD arithmetic, fuzzy logic, mini-mum and maximum, multiply-accumulate, table interpolation.7EE 308 Spring 2003Branch if A > BIs 0xFF > 0x00?If unsigned, 0xFF = 255 and 0x00 = 0, so 0xFF > 0x00 so 0xFF < 0x00If signed, 0xFF = −1 and 0x00 = 0,Using unsigned numbers: BHI (checks C bit of CCR)For unsigned numbers, use branch instructions which check C bitFor signed numbers, use branch instructions which check V bitUsing signed numbers: BGT (checks V bit of CCR)Will the branch be taken?LDAA #$FF LDAA #$FFCMPA #$0 CMPA #$0BLO label1 BLT label2LDX #$C000 LDX #$C000CPX #$8000 CPX #$8000BGT label3 BHI


View Full Document

NMT EE 308 - HCS12 Assembly Language Programming

Documents in this Course
Load more
Download HCS12 Assembly Language Programming
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 HCS12 Assembly Language Programming 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 HCS12 Assembly Language Programming 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?