430 likes | 1.13k Views
BYU CS/ECEn 124. MSP430 Assembler. 2. Topics to Cover. MSP430 AssemblerAssembly ProcessMSP430 AssemblerAssembly DirectivesAssembly SectionsLinkerLibrariesCode Composer Essentials/StudioSystematic DecompositionDevice: LED's. BYU CS/ECEn 124. MSP430 Assembly. 3. Levels of Transformation. Pro
E N D
1. MSP430 Assembler / Linker
2. BYU CS/ECEn 124 MSP430 Assembler 2 Topics to Cover MSP430 Assembler
Assembly Process
MSP430 Assembler
Assembly Directives
Assembly Sections
Linker
Libraries
Code Composer Essentials/Studio
Systematic Decomposition
Device: LEDs
3. BYU CS/ECEn 124 MSP430 Assembly 3 Levels of Transformation
4. BYU CS/ECEn 124 MSP430 Assembly 4 How are we going to proceed?
5. BYU CS/ECEn 124 MSP430 Assembler 5 MSP430 Assembler The assembler is a programming tool that processes assembly source code and produces various outputs
An object file
A descriptive listing of the entire process
A symbol table
An MPS430 assembly source code program contains sequences of statements that may be:
Assembly directives
Assembly instructions
Macros, and/or
Comments.
6. BYU CS/ECEn 124 MSP430 Assembler 6 Assembler
7. BYU CS/ECEn 124 MSP430 Assembler 7 Assembler Syntax Each assembly line begins with either a label, a blank, an asterisk, or a semicolon and can have four fields:
{label[:]} mnemonic {operand list} {;comment}
Some line examples are:
.sect ".sysmem" ; data space
var1 .word 2 ; variable var1 declaration
.text ; program space
loop: mov #COUNT,r5 ; get counter
.end ; end of program
8. BYU CS/ECEn 124 MSP430 Assembler 8 Coding Guidelines General assembly coding guidelines:
All statements must begin with a label, a blank, an asterisk, or a semicolon
Labels are optional - must begin in column 1
Fields are separated by one or more blanks (space or tab)
Comments are optional
Comments that begin in column 1 can begin with an asterisk or a semicolon (* or ;), but comments that begin in any other column must begin with a semicolon
A mnemonic cannot begin in column 1 or it will be interpreted as a label.
9. BYU CS/ECEn 124 MSP430 Assembler 9 Assembly Symbols Symbols
Symbols are used as labels, constants, and substitution values
Symbols are stored in a symbol table
A symbol name is a string of up to 200 alphanumeric characters (A-Z, a-z, 0-9, $, and _)
A symbol cannot contain embedded blanks and the first character cannot be a number
Symbols are case sensitive
Symbols used as labels become symbolic addresses that are associated with locations in the program
Labels used locally within a file must be unique.
10. BYU CS/ECEn 124 MSP430 Assembler 10 Assembly Labels Label Field
Labels are optional
Labels must begin in column 1.
A label can contain up to 128 alphanumeric characters (A-Z, a-z, 0-9, _, and $)
Labels are case sensitive and the first character cannot be a number
A label can optionally be followed by a colon
The value of a label is the current value of the Location Counter (address within program)
A label on a line by itself is a valid statement
11. BYU CS/ECEn 124 MSP430 Assembler 11 Assembly Mnemonics Mnemonic Field
The mnemonic field follows the label field.
The mnemonic field cannot start in column 1; if it does, it is interpreted as a label.
The mnemonic field contains one of the following items:
MSP430 instruction mnemonic (ie. ADD, MOV, JMP)
Assembler directive (ie. .data, .list, .equ)
Macro directive (ie. .macro, .var, .mexit)
Macro call
12. BYU CS/ECEn 124 MSP430 Assembler 12 Assembly Operands Operand Field
The operand field follows the mnemonic field and contains one or more operands.
The operand field is not required for all instructions or directives.
An operand may consist of:
Symbols
Constants
Expressions (combination of constants and symbols)
Operands are separated with commas
13. BYU CS/ECEn 124 MSP430 Assembler 13 Assembly Constants Constants
Decimal #30 = Hex #0x001E
Octal #030 = Decimal #24 = Hex #0x0018
To avoid errors,
Always add a # sign for constants
Dont add extra 0s before a decimal number. Otherwise, it will be treated as an octal number
Always add 0x before a hexadecimal number
For MSP430, it is okay to add 0s to form a 4-digit hexadecimal number
14. BYU CS/ECEn 124 MSP430 Assembler 14 Assembly Expressions Expressions
An expression is a constant, a symbol, or a series of constants and symbols separated by arithmetic operators
An expression evaluates to a 32-bit number
-2147483648 to 2147483647 for signed values
0 to 4294967295 for unsigned values
The precedence order of expression evaluation is
First, evaluate parenthesized expressions
Second, evaluate operators according to precedence groups
Third, when parentheses and precedence groups do not determine the order of expression evaluation, the expressions are evaluated from left to right
15. BYU CS/ECEn 124 MSP430 Assembler 15 Assembly Operators Operators are used in expressions and evaluated according to the following precedence groups:
16. BYU CS/ECEn 124 MSP430 Assembler 16 Assembler Directives Assembly directives are used to specify:
Starting addresses for programs
Starting values for memory locations
Specify the end of program text.
17. BYU CS/ECEn 124 MSP430 Assembler 17 Assembly Process The assembler translates assembly language programs (.asm) into the machine language of the ISA (.obj)
There is a 1-to-1 correspondence between assembly language instructions and instructions in the final machine language
First Pass:
find all labels and their corresponding addresses- this information is stored in the symbol table
Second Pass:
convert instructions to machine language, using information from symbol table
18. BYU CS/ECEn 124 MSP430 Assembler 18
19. BYU CS/ECEn 124 MSP430 Assembler 19 1st Pass: Construct Symbol Table Find the .text statement and zero the Location Counter (LC)
For each non-empty line in the program:
If line contains a label, add label and current LC to the symbol table
If line contains an instruction, increment the LC accordingly
1. All instructions are 2, 4, or 6 bytes in length
2. Some directives like .bss or .string increment LC by the size of the operand.
Stop when .end statement is reached.
20. BYU CS/ECEn 124 MSP430 Assembler 20 2nd Pass: Generate Machine Language Reset location counter (LC)
For each executable assembly language statement, generate the corresponding machine language instruction.
resolve labels referenced in instructions using the symbol table
increment LC for each instruction as in pass 1
output resulting machine code and program listing to output files
Stop when .end statement is reached.
21. BYU CS/ECEn 124 MSP430 Assembler 21 Assembly Style Guidelines Provide a program header, with authors name, date, etc.,and purpose of program.
Start labels, opcode, operands, and comments in same column for each line. (Unless entire line is a comment.)
Use comments to explain what each register does.
Remember, the assembler is case sensitive.
Use meaningful symbolic names.
Mixed upper and lower case for readability.
ASCIItoBinary, InputRoutine, SaveR1
Provide comments between program sections.
Each line must fit on the page -- no wraparound or truncations.
Long statements split in aesthetically pleasing manner.
22. BYU CS/ECEn 124 MSP430 Assembler 22 Assembler directives supply data to the program and control the assembly process
Assembler directives enable you to:
Assemble code and data into specified sections
Reserve space in memory for uninitialized variables
Control the appearance of listings
Initialize memory
Assemble conditional blocks
Define global variables
Specify libraries from which the assembler can obtain macros
Examine symbolic debugging information.
23. BYU CS/ECEn 124 MSP430 Assembler 23 Section Directives Assembler directives that define sections:
24. BYU CS/ECEn 124 MSP430 Assembler 24 Data Directives Assembler directives that initialize constants (data and memory):
25. BYU CS/ECEn 124 MSP430 Assembler 25 Alignment Directives Assembler directives that perform alignment and reserve space:
26. BYU CS/ECEn 124 MSP430 Assembler 26 Output Directives Assembler directives that format the output listing:
27. BYU CS/ECEn 124 MSP430 Assembler 27 Assembly List File A line in a listing file has four fields:
Field 1: contains the source code line counter
Field 2: contains the section program counter
Field 3: contains the object code
Field 4: contains the original source statement.
28. BYU CS/ECEn 124 MSP430 Assembler 28 File Directives Assembler directives that reference other files:
29. BYU CS/ECEn 124 MSP430 Assembler 29 Conditional Directives Assembler directives that enable conditional assembly:
30. BYU CS/ECEn 124 MSP430 Assembler 30 Define Directives Assembler directives that define structures:
Directives that define symbols at assembly time:
31. BYU CS/ECEn 124 MSP430 Assembler 31 Miscellaneous Directives Assembler directives that perform miscellaneous functions:
32. BYU CS/ECEn 124 MSP430 Assembler 32 Most Common Directive Summary
33. BYU CS/ECEn 124 MSP430 Assembler 33 Assembler Sections The smallest unit of an object file is called a section
A section is a block of code or data that occupies contiguous space in the memory map
Each section of an object file is separate and distinct.
Object files contain three default sections:
.text section contains executable code
.data section contains initialized data
.bss section reserves space for uninitialized variables.
34. BYU CS/ECEn 124 MSP430 Assembler 34 Linker Example: process of linking two files together:
35. BYU CS/ECEn 124 MSP430 Assembler 35 Library Routines Library
A set of routines for a specific domain application.
Example: math, graphics, GUI, etc.
Defined outside a program.
Library routine invocation
Labels for the routines are defined as .def
Each library routine contains its own symbol table.
A linker resolves the external addresses before creating the executable image.
36. BYU CS/ECEn 124 MSP430 Assembler 36 Linking multiple files
37. BYU CS/ECEn 124 MSP430 Assembler 37 Code Composer Based on Eclipse framework
Open source enabling rapid innovation
Allows integration with other compilers, plugins
One stop shop with TI
MSP430 + FET Programmer + CCE/S
Support
Direct from TI
Eclipse Community
Third Parties
Low cost solution (Free!)
38. BYU CS/ECEn 124 MSP430 Assembler 38 CCE Window C/C++ Perspective
39. BYU CS/ECEn 124 MSP430 Assembler 39 CCE Window Debug Perspective
40. BYU CS/ECEn 124 MSP430 Assembler 40 The MSP430 Assembler To create a new Assembly language project:
In File -> New Project choose Managed Make C/ASM Project (Recommended)
Assign a name to the project in Project Name, (e.g., stoplight)
Choose Project Type: MSP430 Executable
In Additional Project Setting, do not choose any connection with other projects
In the Device Selection page, select the target device
MSPF2013 or MSP430F2274
Select configuration option: Assembly only Project
At the end of this sequence of operations, a project named stoplight is opened in the work environment
41. BYU CS/ECEn 124 MSP430 Assembler 41 The MSP430 Assembler Assembly project (continued):
Assign a new source code file to the project. In the option Menu > File > Source File and create a new file called stoplight.asm
In the project properties menu, set the entry point as identified by the label start
This option is found on page Build C/C++ build > MSP430 Linker V3.0 > Symbol Management > Specify the program entry point for the output model (-entry point).
42. BYU CS/ECEn 124 MSP430 Assembler 42 The MSP430 Assembly Listing To generate an assembly listing:
Project -> Properties
C/C++ Build -> Tool Settings -> MSP430 Compiler v3.x
Assembler Options:
Check Generate listing file (--asm_listing)
To define program entry point:
Project -> Properties
C/C++ Build -> Tool Settings -> MSP430 Linker v3.x
Symbol Management:
Specify the program entry point for the output model (-- entry point)
Enter the start label
43. BYU CS/ECEn 124 MSP430 Assembly 43 Practice Create a symbol table using the following program that is assembled and loaded into memory beginning at address 0xf800:
44. BYU CS/ECEn 124 MSP430 Assembler 44