Chapter 7 – MSP430 Assembler / Linker

Slides:



Advertisements
Similar presentations
MSP430 Teaching Materials
Advertisements

Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
The Assembly Language Level
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Data types and variables
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Chapter 2 Data Types, Declarations, and Displays
Blinky Lab 3: Blinky Lab Modify the blinky.asm assembly program to blink the LaunchPad red LED quickly on and off at exactly 10 second intervals. Calculate.
Introduction to C Programming
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
Chapter 2 Software Tools and Assembly Language Syntax.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Chapter 8 – Stacks
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
CoE3DJ4 Digital Systems Design
Machine Instruction Characteristics
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Programming With C.
Input, Output, and Processing
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
Computer Science 210 Computer Organization Overview of Assembly Language.
Computer Science 210 Computer Organization More on Assembler.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Computer Science 210 Computer Organization
PROGRAMMING THE BASIC COMPUTER
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Assembly Language Programming of 8085
Chapter 2 - Introduction to C Programming
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
The Selection Structure
Chapter 7 Assembly Language
Chapter 2 - Introduction to C Programming
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
WEB PROGRAMMING JavaScript.
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Chapter 7 Assembly Language
Computer Organization and Assembly Language
8051 ASSEMBLY LANGUAGE PROGRAMMING
Chapter 6 Programming the basic computer
Introduction to C Programming
Chapter 7 Assembly Language
Presentation transcript:

Chapter 7 – MSP430 Assembler / Linker

Chapter 7 - MSP430 Assembler Concepts to Learn… MSP430 Assembler High Level vs. Assembly Assembly Code Assembly Process Assembly Directives Assembly Sections Linker Libraries Code Composer Essentials/Studio Systematic Decomposition Device: LED’s BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Moving Up Levels of Abstraction Problems Algorithms Language Assembly code Machine (ISA) Architecture Machine code Micro-architecture LC-3 Architecture Circuits Logic gates, multiplexers, memory, etc. Devices Transistors BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Assembler Assembler An assembler outputs an object file as input to a linker program An assembler translates a program into machine code An assembly program is a text file BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 4

Chapter 7 - MSP430 Assembler High Level vs. Assembly High Level vs. Assembly High Level Languages More programmer friendly More ISA independent Each high-level statement translates to several instructions in the ISA of the computer Assembly Languages Lower level, closer to ISA Very ISA-dependent Each instruction specifies a single ISA instruction Makes low level programming more user friendly More efficient code BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler High Level vs. Assembly Why Assembly Code? Allows us to work at a slightly higher level than machine language. Allows us to use symbolic names for opcodes Allows us to use symbolic names for memory locations - SUM, PRODUCT Don’t need to know every address of every storage location. Calculates addresses for us – really a big deal! Helps to allocate memory locations. Provides additional error checking BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembly Code Assembly Code Example ;******************************************************************************* ; CS/ECEn 124 Lab 4 - morse.asm: Student Code .cdecls C,LIST, "msp430x22x4.h“ ; include C header COUNT .equ 2000 ;------------------------------------------------------------------------------ .data ; data .bss cnt,2 ; ISR counter .text ; Program reset RESET: mov.w #0x0280,SP ; Initialize stack pointer mov.w #WDT_MDLY_0_5,&WDTCTL ; Set Watchdog interval to ~0.5ms mov.b #WDTIE,&IE1 ; Enable WDT interrupt bis.b #0x01,&P1DIR ; P1.0 output bis.b #0x20,&P4DIR ; P4.0 output mov.w #COUNT,&cnt ; initialize counter bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt jmp $ ; Loop forever; interrupts do all ; Watchdog Timer interrupt service routine ; WDT_ISR: xor.b #0x20,&P4OUT ; pulse buzzer dec.w &cnt ; decrement counter jne WDT_exit xor.b #0x01,&P1OUT ; toggle P1.0 WDT_exit: reti ; return from interrupt .sect ".int10" ; MSP430 RESET Vector .word WDT_ISR ; Watchdog ISR .sect ".reset" ; MSP430 RESET Vector .word RESET ; Power Up ISR .end Instructions Labels Comments Directives BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax The MSP430 assembler reads up to 200 characters per line. Any characters beyond 200 are truncated. Follow these guidelines: All statements must begin with a label, a blank, an asterisk, or a semicolon Labels are optional; if used, they must begin in column 1 One or more blanks must separate each field. Tab and space characters are blanks. 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 [label[:]]mnemonic [operand list][;comment] BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 8

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax Label Field Labels are optional for all assembly language instructions and for most (but not all) assembler directives When used, a label 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 be followed by a colon (:). (If you do not use a label, the first character position must contain a blank, a semicolon, or an asterisk) The value of a label is the current value of the Location Counter A label on a line by itself is a valid statement If you do not use a label, the character in column 1 must be a blank, an asterisk, or a semicolon BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 9

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax 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 can begin with one of the following items: Machine-instruction mnemonic (such as ADD, MOV, JMP) Assembler directive (such as .data, .list, .equ) Macro directive (such as .macro, .var, .mexit) Macro call BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 10

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax 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 consists of the following items: Symbols Constants Expressions (combination of constants and symbols) You must separate operands with commas You use immediate values as operands primarily with instructions Use the # prefix to define an immediate value BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 11

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax Constants The assembler maintains constants internally as a 32-bit quantities Constants are not sign extended (ie, 00FFh is equal to 00FF (base 16) or 255 (base 10); however, it does not equal -1 unless a byte directive) Types of constants: Decimal: string of decimal digits ranging from (-2147483648 to 4294967295 (ie, 1000, -32768) Hexadecimal: string of up to 8 hexadecimal digits followed by suffix ‘H’ (or ‘h’) or preceded by ‘0x’ (ie, 78h, 0x78) Binary: string of upt to 32 binary digits followed by suffix B (or b) (ie. 0000b, 11110000B) BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 12

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax Expressions An expression is a constant, a symbol, or a series of constants and symbols separated by arithmetic operators. The 32-bit ranges of valid expression values are -2147 483 648 to 2147 483 647 for signed values, and 0 to 4 294 967 295 for unsigned values. Three main factors influence the order of expression evaluation: Parentheses Expressions enclosed in parentheses are always evaluated first. (You cannot substitute braces ( { } ) or brackets ( [ ] ) for parentheses) 8 / (4 / 2) = 4, but 8 / 4 / 2 = 1 Precedence groups Operators: when parentheses do not determine the order of expression evaluation, the highest precedence operation is evaluated first. 8 + 4 / 2 = 10 (4 / 2 is evaluated first) Left-to-right evaluation: when parentheses and precedence groups do not determine the order of expression evaluation, the expressions are evaluated from left to right BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 13

Chapter 7 - MSP430 Assembler Assembly Code Assembly Syntax Operators can be used in expressions and are evaluated according to precedence group Group Operator Description 1 +, -, ~, ! Unary plus, minus, 1’s complement, Logical NOT 2 *, /, % Multiplication, Division, Modulo 3 +, - Addition, Subtraction 4 <<, >> Shift left, Shift right 5 <, <=, >, >= Less than, Less than or equal to, Greater than, Greater than or equal to 6 =[=], != Equal to, Not equal to 7 & Bitwise AND 8 ^ Bitwise exclusive OR (XOR) 9 | Bitwise OR BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 14

Chapter 7 - MSP430 Assembler Assembly Code Assembler Directives Assembly directives are used to specify: Starting addresses for programs Starting values for memory locations Specify the end of program text. ;******************************************************************************* ; CS/ECEn 124 Example Code .cdecls C,LIST, "msp430x22x4.h“ ; include C header COUNT .equ 2000 ;------------------------------------------------------------------------------ .data ; data .bss cnt,2 ; ISR counter .text ; Program reset RESET: mov.w #0x0280,SP ; Initialize stack pointer mov.w #WDT_MDLY_0_5,&WDTCTL ; Set Watchdog interval to ~0.5ms bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt jmp $ ; Loop forever; interrupts do all .sect ".reset" ; MSP430 RESET Vector .word RESET ; Power Up ISR .end Directives BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembly Process 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 BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

1st Pass: Construct Symbol Table Assembly Process 1st Pass: Construct Symbol Table Find the .text statement, which tells us the address of the first instruction Initialize location counter (LC) Incremented for each new instruction For each non-empty line in the program: If line contains a label, add label and LC to symbol table. Increment LC (according to instruction length.) 1. All instructions are 1, 2, or 3 words in length 2. Some directives like .bss or .string increment LC by the size of the operand. Stop when .end statement is reached. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

2nd Pass: Generate Machine Language Assembly Process 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 on pass 1 output resulting machine code to output files Stop when .end statement is reached. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Assembly Style Guidelines Assembly Process Assembly Style Guidelines Provide a program header, with author’s 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler The MSP430 assembler translates your source code into machine language Source files may contain the following elements: Assembly directives Macro directives Assembly language instructions For more detailed information on each element, please refer to the MSP430 Assembly Language Tools User’s Guide (slau131b.pdf) Some of the most relevant aspects of the assembly language for the MSP430 will now be introduced BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Stoplight Example ;******************************************************************************* ; CS/ECEn 124 Lab 4 - stoplight.asm: Software Toggle P1.0 .cdecls C,LIST, "msp430x22x4.h" ; MSP430F2274 ;------------------------------------------------------------------------------ .text ; beginning of executable code RESET: mov.w #0x0280,SP ; init stack pointer mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop WDT bis.b #0x01,&P1DIR ; set P1.0 as output mainloop: xor.b #0x01,&P1OUT ; toggle P1.0 mov.w #0,r15 ; use R15 as delay counter delayloop: dec.w r15 ; delay over? jnz delayloop ; n jmp mainloop ; y, toggle led ; Interrupt Vectors .sect ".reset" ; MSP430 RESET Vector .short RESET ; start address .end BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler The assembly programming tool processes the source code, producing an object file, and a descriptive listing of the entire process This process is completely controlled by macros, allowing conditional execution The MPS430 source code programs contains sequences of statements that have: Assembly directives Assembly instructions Macros, and Comments. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Syntax A line can have four fields label, mnemonic, operand list, and comment The general syntax is: {label[:]} mnemonic {operand list} {;comment} Some line examples are: .sect ".sysmem“ ; Data Space var1 .word 2 ; variable var1 declaration .text ; Program Space Label1: mov r4,r5 ; move R4 contents to R5 .end BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Coding Guidelines The general coding guidelines: All statements must begin with a label, a blank, an asterisk, or a semicolon Labels are optional. If used, they must begin in column 1 One or more blanks or tabs must separate each field 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Constants The assembler supports several formats for constants: Binary integer: 11110000b  0xf0 Octal integer: 226q  0x96 Decimal integer: 25  0x19 Hexadecimal integer: 078h  0x78 Character: a  'a' Assembly time: value1  value1 .set 3 BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Symbols Symbols are used as labels, constants, and substitution symbols 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembly Directives Assembler Directives 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Section Assembler Directives Assembler directives that define sections: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that initialize constants (data and memory): BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that perform alignment and reserve space: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that format the output listing: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that reference other files: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that enable conditional assembly: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that define structures: Directives that define symbols at assembly time: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Directives Assembler Directives Assembler directives that perform miscellaneous functions: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Assembler Sections 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Linker Linker Example: process of linking two files together: BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Libraries 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. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Linking multiple files Libraries Linking multiple files BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Code Composer 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 Support Direct from TI Eclipse Community Third Parties Low cost solution (Free!) BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 41

CCE Window – C/C++ Perspective Code Composer CCE Window – C/C++ Perspective 1-click project debug Independent debugging and Programming view Project View List of all Projects Project Outline Shortcut to all parts of the project Code Window Real-time breakpoints Syntax highlighting Problems View Information Warnings Errors Console Build information BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 42

CCE Window – Debug Perspective Code Composer CCE Window – Debug Perspective 1-click project debug Independent debugging and Programming view Target control Start, stop, halt Single stepping Stack trace Real-time, in-system MSP430 information Register access Flash, RAM, Info segment access Disassembly view Code Window Real-time breakpoints Syntax highlighting Highly configurable window layout User preferences Plugin support Easy to view program size info CPU Cycle counter BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler 43

Chapter 7 - MSP430 Assembler Code Composer 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 BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Code Composer 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). BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

The MSP430 Assembly Listing Code Composer 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: 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 BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Systematic Decomposition IDEA Step by Step Procedure Finiteness Must terminate. Definiteness Each step is precisely stated. Effective Computability Each step can be carried out. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Systematic Decomposition Stepwise Refinement Also known as incremental development. Start with problem statement: “Write an assembler program for a traffic stop light.” Decompose task into a few simpler subtasks. Turn on the green LED for 5 seconds. Blink the green LED on and off at 1 second intervals for 6 seconds (3 offs and 3 ons). Blink the green LED on and off at 0.25 second intervals for 4 seconds (8 offs and 8 ons). And finally, turn the green LED off for 10 seconds. Repeat the process of dividing into subtasks until you get to the machine instruction level. BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Systematic Decomposition F2274 Stoplight Example ;******************************************************************************* ; CS/ECEn 124 Lab 4 - stoplight.asm: Software Toggle P1.0 .cdecls C,LIST, "msp430x22x4.h" ; MSP430F2274 ;------------------------------------------------------------------------------ .text ; beginning of executable code RESET: mov.w #0x0280,SP ; init stack pointer mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop WDT bis.b #0x01,&P1DIR ; set P1.0 as output mainloop: xor.b #0x01,&P1OUT ; toggle P1.0 mov.w #0,r15 ; use R15 as delay counter delayloop: dec.w r15 ; delay over? jnz delayloop ; n jmp mainloop ; y, toggle led ; Interrupt Vectors .sect ".reset" ; MSP430 RESET Vector .short RESET ; start address .end BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Device: LED LEDs A light-emitting diode (LED) is a semiconductor light source When a diode is forward biased (switched on), electrons are able to recombine with holes within the device, releasing energy in the form of photons BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Device: LED LEDs 6 LED’s on eZ430X Development Board P1.0 Red LED eZ430-RF2500 P1.1 Green LED eZ430-RF2500 P2.6 LED #1 (Green) P2.7 LED #2 (Orange) P3.3 LED #3 (Yellow) P4.6 LED #4 (Red) Port bits must be enabled for output by writing a 1 to the port direction register bis.b #0x03,&P1DIR ; eZ430-RF2500 LED's bic.b #0xc0,&P2SEL ; select GPIO bis.b #0x40,&P2DIR ; LED #1 (P2.6) bis.b #0x80,&P2DIR ; LED #2 (P2.7) bis.b #0x08,&P3DIR ; LED #3 (P3.3) bis.b #0x40,&P4DIR ; LED #4 (P4.6) BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler Device: LED LEDs Turn LED off by writing a 0 to the port pin bic.b #0x03,&P1OUT ; eZ430-RF2500 LED's bic.b #0x40,&P2OUT ; LED #1 (P2.6) bic.b #0x80,&P2OUT ; LED #2 (P2.7) bic.b #0x08,&P3OUT ; LED #3 (P3.3) bic.b #0x40,&P4OUT ; LED #4 (P4.6) Turn LED on by writing a 1 to the port pin bis.b #0x03,&P1OUT ; eZ430-RF2500 LED's bis.b #0x40,&P2OUT ; LED #1 (P2.6) bis.b #0x80,&P2OUT ; LED #2 (P2.7) bis.b #0x08,&P3OUT ; LED #3 (P3.3) bis.b #0x40,&P4OUT ; LED #4 (P4.6) Toggle LED by XOR’ing a 1 to the port pin xor.b #0x03,&P1OUT ; eZ430-RF2500 LED's xor.b #0x40,&P2OUT ; LED #1 (P2.6) xor.b #0x80,&P2OUT ; LED #2 (P2.7) xor.b #0x08,&P3OUT ; LED #3 (P3.3) xor.b #0x40,&P4OUT ; LED #4 (P4.6) BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Chapter 7 - MSP430 Assembler BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler

Most Commonly Used Directives Mnemonic and Syntax Description .bss symbol, size in bytes[, alignment] Reserves size bytes in the .bss (uninitialized data) section .data Assembles into the .data (initialized data) section .sect " section name" Assembles into a named (initialized) section .text Assembles into the .text (executable code) section .byte value1[, ..., valuen] Initializes one or more successive bytes in the current section .char value1[, ..., valuen] .string {expr1|"string1"}[,... , {exprn|"stringn"}] Initializes one or more text strings .word value1[, ... , valuen] Initializes one or more 16-bit integers .align [size in bytes] Aligns the SPC on a boundary specified by size in bytes, which must be a power of 2; defaults to word (2 byte) .title " string " Prints a title in the listing page heading .def symbol1[, ... , symboln] Identifies one or more symbols that are defined in the current module and that can be used in other modules .include ["]filename["] Includes source statements from another file .ref symbol1[, ... , symboln] Identifies one or more symbols used in the current module that are defined in another module .else Assembles code block if the .if well-defined expression is false. (Optional) .elseif well-defined expression Assembles code block if the .if well-defined expression is false and the .elseif condition is true. (Optional) .endif Ends .if code block .if well-defined expression Assembles code block if the well-defined expression is true symbol .equ value Equates value with symbol symbol .set value .cdecls [options,] "filename"[, "filename2"[, ...] Share C headers between C and assembly code .end Ends program BYU CS/ECEn 124 Chapter 7 - MSP430 Assembler