Académique Documents
Professionnel Documents
Culture Documents
Assembly Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Statements and Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 User Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Source Statement Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Fields Continued . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Assembler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Freescale Assembler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Freescale Assembler Directives Cont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Codewarrior Assembler Directive: Absentry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Codewarrior Assembler Directive: DC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Codewarrior Assembler Directive: DC & DS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Assembled DC Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Codewarrior Assembler Directive: EQU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Codewarrior Assembler Directive: ORG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Codewarrior Assembler Directive: Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Codewarrior Assembly Directive: Section Cont. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Codewarrior Assembler Directive: XDEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 OFFSET - Create absolute symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 OFFSET Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Review Question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Review Question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Assembly Language
s s s
Generic Assembler Concepts (Slides 3 - 8) Codewarrior Assembler Specics Review EE 3381 Microprocessors jkb 5 slide 2
Source Statement is a single line of the source program. Source statement may contain various numbers and symbols. Numbers and symbols are connected by operators to make a sentence. Spaces, tabs are important. They serve as delimiters or separators.
Numbers are represented by decimal, hexadecimal, or binary. Decimal Decimal Hexadecimal Hexadecimal Binary 10 -100 $10 $ABCD %1001 A positive number A negative number Preceeded by $ Binary number preceeded by %
Comment: Always use the preceding dollar or percent signs. Common Mistake The assembly process converts negative numbers to 2s complement numbers. EE 3381 Microprocessors jkb 5 slide 3
User Symbols
MNEMONICS - LDAA, ldaa, STAA, staa, ... Symbols consists of alphanumeric characters. The 1st character must be alphabetic. User dened symbols May not consist of the single characters A, B, X, Y. Also do not dene symbols after the mnemonics. Each symbol must be unique Examples: TIME, INIT4, A444. Incorrect: 3ABC, 125, A Combination of symbols, +, -, * and / are called expressions. Example: ABC + 1 ; add 1 to the symbol ABC EE 3381 Microprocessors jkb 5 slide 4
EE 3381 Microprocessors
jkb 5 slide 5
Fields
LABEL User dened symbol represents an address. Label starts in column 1.
OPERATION FIELD Instruction mnemonics Example START CLRA START is the label and CLRA is the operation. OPERAND FIELD Depends on the operator. May be empty, symbol, number, or expression. Example LOOP LDAA NUMBER ;a Comment LOOP is the label, LDAA is the operation, NUMBER is the operand, and Commnet is an optional comment.
The semicolon is used in blank lines and always preceeds a comment. Some assemblers use a star, *, to designate a blank line or the beginning of a comment.
a
EE 3381 Microprocessors
jkb 5 slide 6
Fields Continued
Addressing Mode Inherent Immediate Extended Direct Indexed Prog. Rel. Operand Format None #Operand Operand Operand Operand,X Operand Operand Type None Number 2-byte address 1-byte address Offset Offset jkb 5 slide 7
EE 3381 Microprocessors
Assembler Directives
Directives control the operation of the assembler. For example, the ORGa directive puts an address in the assembler location counter that species the location of the code in memory. ORG expression Example: ORG $C800 ORG 25
a
The ORG assembler directive will be discussed in more detail in slide 16.
EE 3381 Microprocessors
jkb 5 slide 8
DCW (= 2 byte DCs), DCL (= 4 byte DCs), FCB (= DC.B), FDB (= 2 byte DCs), FQB (= 4 byte DCs) The DC directive denes constants in memory. It can have one or more <expression> operands, which are separated by commas. The <expression> can contain an actual value (binary, octal, decimal, hexadecimal, or ASCII). Alternatively, the <expression> can be a symbol or expression that can be
evaluated by the Assembler as an absolute or simple relocatable expression. One memory block is allocated and initialized for each expression.
a b
See HC(S)12 Assembler Manual, page 288. Something with brackets [] implies it is optional, and not part of RTL.
EE 3381 Microprocessors
jkb 5 slide 12
;Puts 0F into memory. ; Puts 0F into memory. ; Puts 27, 0C, 22 into memory.
Dene Constant Words WHAT: DC.W Hello LARGE: DC.W $0C3D Dene Storage
a
; Puts 48, 65, 6C, 6C, 6F into memory. ;Puts 0C, 3D into memory. 2 5 ; Reserves 2 bytes of memory. ; Reserves 5 words or 10 bytes of memory.
NEW1: NEW2:
DS.B DS.W
EE 3381 Microprocessors
jkb 5 slide 13
Assembled DC Directive
Label: DC.B "ABCDE" DC.B %1010, @12, 1,$A
Freescale HC12-Assembler (c) Copyright Freescale 1987-2008 Abs. Rel. ---- ---1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 Loc Obj. code -------------Source line ----------;The Freescale Assembler ; Example of simple assembler directives ; Source 5.1.asm ; Jerome K. Butler ; February 16, 2009 ; ORG $4000 ; ORG will start code $4000 Label: DC.B "ABCDE" DC.B %1010, @12, 1,$A
EE 3381 Microprocessors
jkb 5 slide 14
symbola EQU expression EQU is similar to #dene something in C/CPP, such as, #dene PI 314 The compiler simply replaces the string PI with the number 314. Example: PI EQU 314 Makes the code: LDD #PI Equivalent to: LDD #314
a
EE 3381 Microprocessors
jkb 5 slide 15
EE 3381 Microprocessors
jkb 5 slide 16
EE 3381 Microprocessors
jkb 5 slide 17
EE 3381 Microprocessors
jkb 5 slide 19
EE 3381 Microprocessors
jkb 5 slide 20
OFFSET Example
Freescale HC12-Assembler (c) Copyright Freescale 1987-2008 Abs. Rel. ---- ---1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 Loc Obj. code -------------0000 0001 0003 0000 0007 0000 Source line ----------OFFSET ID: DS.B COUNT: DS.W VALUE: DS.L SIZE: EQU ;; DataSec: SECTION Struct: DS.B ;; CodeSec: SECTION entry: LDX LDAA STAA INC INCA STAA
0 1 1 1 * SIZE
EE 3381 Microprocessors
jkb 5 slide 21
Review Question
This question is similar to 5.13/page 103 Give the result in hexadecimal for each of the following assembler expressions. [k] MS MASK EQU %11110000 LS MASK EQU %00001111 MOST EQU 255 NEG EQU -128 SIX EQU 6 TEN EQU 10 DATA1: DS.B 10 DATA2: DC.B 10 EE 3381 Microprocessors jkb 5 slide 22
Review Question
Freescale HC12-Assembler (c) Copyright Freescale 1987-2008 Abs. Rel. ---- ---1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 Loc Obj. code -------------0000 0000 0000 FFFF 0000 0000 a2000 a200A 0A a200B 10 a200C 0A 00F0 000F 00FF FF80 0006 000A Source line ----------;; ORG $2000 MS_MASK EQU %11110000 LS_MASK EQU %00001111 MOST EQU 255 NEG1 EQU -128 SIX EQU 6 TEN EQU 10 DATA1: DS.B 10 DATA2: DC.B 10 Q1: DC.B SIX+TEN Q2: DC.B DATA2-DATA1 ;; This is not [DATA2]-[DATA1].
EE 3381 Microprocessors
jkb 5 slide 23