U of U CS 5780 - Assembly Language Programming

Unformatted text preview:

ECE/CS 5780/6780: Embedded System DesignScott R. LittleLecture 3: Assembly Language ProgrammingScott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 1 / 59Administrivia2 versions of CodeWarrior are on the lab machines.You should use the 4.5 version (CW for HC12 v 4.5).Lab 1 was updated yesterday morning.Both team members need to be present for check-off.Lab reports don’t need to be in ”report” format.Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 2 / 59Assembly Language Development ProcessScott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 3 / 59Assembly Language SyntaxLabel Operation Operand CommentPORTA equ $0000 ; Assembly time constantInp ldaa PORTA ; Read data from PORTAIf first character of label is “∗” or “;”, then line is a comment.If first character is white space, then there is no label.Labels composed of characters, digits, “.”, “$”, or “ ”, andmust start with a character, “.”, or “ ”, and are case-sensitive.Labels should be defined only once except those defined by set.With exception of equ and set, a label is assigned value ofprogram counter for the next instruction or assembler directive.A label may have an optional “:” which is ignored or be on aline by itself.Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 4 / 59Assembly Language Syntax (cont)Operations must be proceede d by at least one white spacecharacter, and they are case-insensitive (nop, NOP, NoP).Operations can be an opcode or assembler directive (pseudo-op).Operand must be procee ded by white space.Operands must not contain any white space unless the followingcomment begins with a semicolon.Operands are composed of symb ols or expressions.Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 5 / 59Operand TypesOperand Format Exampleno operand INH clra#<expression> IMM ldaa #4<expression> DIR,EXT,REL ldaa 4<expression>,idx indexed (IND) ldaa 4,x<expr>,#<expr> bit set or clear bset 4,#$01<expr>,#<expr>,< expr > bit test & branch brset 4,#$01,foo<expr>,idx,#<expr>,< expr > bit test & branch brset 4,x,#$01,foo<expression>,idx+ IND, post incr ldaa 4,x+<expression>,idx- IND, post decr ldaa 4,x-<expression>,+idx IND, pre incr ldaa 4,+x<expression>,-idx IND, pre decr ldaa 4,-xacc,idx accum offset IND ldaa A,x[<expression>,idx] IND indirect ldaa [4,x][D,idx] RegD IND indirect ldaa [D,x]Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 6 / 59Indexed Addressing ModeUses a fixed signed offset with a 16-bit register: X, Y, SP, or PC.Offset can be 5-bits, 9-bits, or 16-bits.Example (5-bit):Obj code Op Operand Comment$6A5C staa -4,Y ;[Y-4] = RegAScott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 7 / 59Building the Object Codestaa -4,Y → $6A5CFirst byte is $6A - Op code (pg. 254)Second byte is formatted as %rr0nnnnn (pg. 33).rr is %01 for register Y.nnnnn is %11100 for -4.%0101 1100 → $5C.Information is found in the CPU12 Reference Manual(CPU12RM.pdf).Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 8 / 59Auto Pre/Post Decrement/Increment IndexedCan be used with the X, Y, and SP registers, but not PC.The register used is i ncreme nted/decreme nted by the offset value(1 to 8) either before (pre) or after (p ost) the me mory access.In these examples assume that RegY=2345:Op Operand Commen tstaa 1,Y+ ;Store RegA at 2345, then RegY=2346staa 4,Y- ;Store RegA at 2345, then RegY=2341staa 4,+Y ;RegY=2349, then store RegA at 2349staa 1,-Y ;RegY=2344, then store RegA at 2344Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 9 / 59Building the Object Codestaa 1,X+ → $6A30First byte is $6A - Op code (pg. 254)Second byte is formatted as %rr1pnnnn (pg. 33).rr is %00 for register X.nnnn is %0000 for 1.p is %1 for post.%0011 0000 → $30.Information is found in the CPU12 Reference Manual(CPU12RM.pdf).Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 10 / 59Accumulator Offset IndexedUses two registers, offset is in A, B, or D, while index is in X, Y,SP, or PC.Examples:Op Operand Commen tldab #4ldy #2345staa B,Y ;Store value in RegA at 2349Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 11 / 59Indexed IndirectAdds 16-bit offset to 16-bit register (X,Y,SP, or PC) to computeaddress in which to fetch another address.This second address is used by the load or store.Examples:Op Operand Commen tldy #$2345staa [-4,Y] ;Fetch 16-bit address from $2341,;store $56 at $1234Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 12 / 59Accumulator D Offset Indexed IndirectOffset is in D and index is in another 16-bit register.Computed addressed is used to fetch another address frommemory.Load or store uses the second address.Examples:Op Operand Commentldd #4ldy #$2341stx [D,Y] ;Store value in RegX at $1234Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 13 / 59Load Effective AddressUsed with IND addressing modes.Calculate the effective address and store it in the sp ec ifiedregister: X, Y, or SP.CC bits are not affected.Example:leas -4,SP ;SP -= 4 → $1B9C$1B is leas op code (first byte).Second byte is %rr0nnnnn.%10 is the rr code for SP.%1 1100 is -4.Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 14 / 59Load and Store InstructionsUsed to move data to (from) registers from (to) memory.Load instructions are: ldaa, ldab, ldd, lds, ldx, and ldy.Load addressing modes are: IMM, DIR, EXT, IND.Store instructions are: staa, stab, std, sds, sdx, and sdy.Store addressing modes are: DIR, EXT, IND.CC bits N and Z are updated based on data loaded or stored.Examples:Op Operand Commen tldaa #$FF IMMstaa $25 DIRldab $0025 EXTstd $05,X INDldd $C025 EXTScott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 15 / 59Memory to Memory Move InstructionsUsed to move constant into memory or the value of one memorylocation into another.CC bits are not affected by these i nstructions.Move an 8-bit constant into memory:movb #w,addr [addr]=wMove an 8-bit value memory to memory:movb addr1,addr2 [addr2]=[addr1]Move a 16-bit constant into memory:movw #W,addr {addr}=WMove a 16-bit value memory to memory:movw addr1,addr2 {addr2}={addr1}Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780 16 / 59Clear/Set InstructionsUsed to initialize memory (clr), accumulators (clra,clrb), orbits in the CC (clc, cli, clv).clr addressing modes are: EXT, IND.clra, clrb, clc, cli, clv are INH.Examples:Op Operand Commen tclra INHclr $0025 EXTThe carry (C), interrupt mask (I), and overflow (V) bits in theCC can also be set (sec, sei, sev).Scott R. Little (Lecture 3: Assembly) ECE/CS 5780/6780


View Full Document

U of U CS 5780 - Assembly Language Programming

Documents in this Course
Lab 1

Lab 1

5 pages

FIFOs

FIFOs

10 pages

FIFOs

FIFOs

5 pages

FIFO’s

FIFO’s

12 pages

MCU Ports

MCU Ports

12 pages

Serial IO

Serial IO

26 pages

Load more
Download 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 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 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?