Getting Started with the MSP430 IAR Assembly

Similar documents
CPE 323: Laboratory Assignment #1 Getting Started with the MSP430 IAR Embedded Workbench

CPE 323 MSP430 MSP430 Assembly Language Programming

CPE 323 Introduction to Embedded Computer Systems: MSP430: Assembly Language and C. Instructor: Dr Aleksandar Milenkovic Lecture Notes

CPE/EE 323 Introduction to Embedded Computer Systems Homework III

Lecture test next week

Before next weeks lab:

PHYS 319. Things to do before next week's lab Whirlwind tour of the MSP430 CPU and its assembly language Activity 1.

Today's plan: Announcements General Strategy Microcontroller programming concepts/last bits of assembly Activity 2

Create and Add the Source File

Programming in the MAXQ environment

MIDTERM#1. 2-(3pts) What is the difference between Von Neumann & Harvard processor architectures?

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

Development Tools. 8-Bit Development Tools. Development Tools. AVR Development Tools

Getting Started with the Texas Instruments ez430

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

The board contains the connector for SWD bus to implement SWD method of programming. Fig. K190 VDD 2 GND 4

Block diagram of processor (Harvard)

CPE 323 Introduction to Embedded Computer Systems: MSP430 System Architecture An Overview

IAR C-SPY Hardware Debugger Systems User Guide

Using Code Composer Studio IDE with MSP432

IAR C-SPY Hardware Debugger Systems User Guide. for Renesas E30A/E30 Emulators

CPU: SOFTWARE ARCHITECTURE INSTRUCTION SET (PART

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

ME 4447/ME Microprocessor Control of Manufacturing Systems/ Introduction to Mechatronics. Instructor: Professor Charles Ume

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and IAR compiler Document Rev. 5

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.1 Revision: 0 Date: May 3, 2018

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually.

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

Embedded Systems. 2. Software Development. Lothar Thiele. Computer Engineering and Networks Laboratory

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.0 Revision: 0 Date: September 18, 2017

NEW CEIBO DEBUGGER. Menus and Commands

Alex Milenkovich 1. CPE/EE 421 Microcomputers: The MSP430 Introduction. Outline

General issues. Format MACROS. Example 1: Extract MS nibble of register A as Lsnibble of Reg. B 7/11/2014

General issues MACROS

Chapter 7 Central Processor Unit (S08CPUV2)

8051 Microcontrollers

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

Lecture 6. Assembler Directives

Pragma intrinsic and more

MetaWatch Firmware Design Guide

ST6-SW SOFTWARE DEVELOPMENT TOOLS FOR ST6 MCU FAMILY

CMS-8GP32. A Motorola MC68HC908GP32 Microcontroller Board. xiom anufacturing

Using peripherals on the MSP430 (if time)

Programming Model 2 A. Introduction

Hacettepe University

Timer Module Timer A. ReadMeFirst

ORG ; TWO. Assembly Language Programming

Texas Instruments Mixed Signal Processor Tutorial Abstract

Introduction to the SX Microcontroller

IAR EWARM Quick Start for. Holtek s HT32 Series Microcontrollers

8051 Microcontroller

M16C/62P QSK QSK62P Plus Tutorial 1. Software Development Process using HEW4

CPE 323: MSP430 Timers

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Week 4: Embedded Programming Using C

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Chapter 09. Programming in Assembly

M32C Simulator Debugger V.1.03

ELEG3924 Microprocessor

PICMICRO C-SPY. User Guide

Assembly Language programming (1)

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

SKP16C26 Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:


Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Tutorial 1: Programming Model 1

Embedded and Ambient Systems Laboratory

CEIBO FE-5131A Development System

Basic Assembly SYSC-3006

AN HONORS UNIVERSITY IN MARYLAND UMBC. AvrX. Yousef Ebrahimi Professor Ryan Robucci

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

H8 C-SPY. User Guide WINDOWS WORKBENCH VERSION

Interrupts CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

CEIBO FE-5111 Development System

Getting Started. with IAR Embedded Workbench GSEW-2

CPE/EE 421 Microcomputers

8086 ALP TOOLS (CH 2) CHAPTER 2

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

ME 4447/6405 Introduction to Mechatronics Instructor: Professor Charles Ume

IAR Assembler User Guide

Why embedded systems?

Lab 1: I/O, timers, interrupts on the ez430-rf2500

The output from XLINK is executable code that can be downloaded to the flash controller, or simulated in AVR Studio.

Department of Electronics and Instrumentation Engineering Question Bank

CONTENTS: Program 1 in C:

embos Real Time Operating System CPU & Compiler specifics for Texas Instruments MSP430 CPUs and Rowley compiler for MSP430 Document Rev.

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

embos Real Time Operating System CPU & Compiler specifics for ARM core with ARM RealView Developer Suite 3.0 Document Rev. 1

esi-risc Development Suite Getting Started Guide

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

The ThreadX C-SPY plugin

Lecture 03 Bits, Bytes and Data Types

Design UART Loopback with Interrupts

Using the KD30 Debugger

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

Introduction to the ThreadX Debugger Plugin for the IAR Embedded Workbench C-SPYDebugger

Transcription:

Getting Started with the MSP430 IAR Assembly by Alex Milenkovich, milenkovic@computer.org Objectives: This tutorial will help you get started with the MSP30 IAR Assembly program development. You will learn the following topics: Assembly programming Creating an application project using assembly programs Debugging using the IAR C-SPY Debugger (Simulator) Note: It is required that students have completed the tutorial Getting Starting With MSP430 IAR Embedded Workbench before starting with this one. 1. Count Number of Characters E in a String: Problem Statement This section defines the problem that will be solved by the Count Characters program using MSP430 assembly language. Our task is to develop an assembly program that will scan a given string of characters, for example, HELLO WORLD, I AM THE MSP430!, and find the number of appearances of the character E in the string. A counter that records the number of characters E is then written to the parallel port P1. The port should be configured as an output port, and the binary value of the port will correspond to the counter value. Step 1: Analyze the assignment and develop a plan. To solve this assignment, let us first analyze the problem statement. Your task is to write an assembly program that will count the number of characters E in a string. First, the problem implies that we need to allocate space in memory that will keep the string HELLO WORLD, I AM THE MSP430!. The string has 29 characters and they are encoded using ASCII table. To allocate and initialize a string in memory we can use an assembly language directive, for example DB (Define Byte). DB "HELLO WORLD, I AM THE MSP430!" We can also put a label to mark the beginning of this string in memory, for example, mystr: mystr DB "HELLO WORLD, I AM THE MSP430!" When assembler sees the DB directive, it will allocate the space in memory required for the string that follows and initialize the allocated space with ASCII characters. The assembler will also automatically add an ASCII NULL character at the end of each string (ascii(null)=0x00). So, the total number of bytes occupied by this string is 30.

Step 2. Develop a plan. Our task is now to write a small program that will scan the string, character by character, check whether the current character is equal to character E, and if yes, increment a counter. The string scan is done in a program loop. The program ends when we reach the end of the string which is detected when the current character is equal to the NULL character (0x00). To scan the string we will use a register to point to the current character in the string. This pointer register is initialized at the beginning of the program to point to the first character in the string. The pointer will be incremented in each iteration of the program loop. Another register, initialized to zero at the beginning, will serve as the counter, and it is incremented every time the current character is E. After we exit the program loop, the current value of the counter will be written to the port P1, which should be initialized as an output port. Note: it is required that you are familiar with the MSP430 instruction set and addressing modes to be able to solve this problem. We assume that the string is no longer than 255 characters, so the result can be displayed on an 8-bit port. 2. Count Characters: Assembly Code Figure 1 shows the assembly code for this program. Here is a short description of the assembly code. 1. The comments in a single line start with a column character (;). Multi-line comments can use C-style /* comment */ notation. 2. #include <msp430xg46x.h>; This is a C-style pre-processor directive that specifies a header file to be included in the source. The header file includes all macro definitions, for example, special function register addresses (WDTCTL), and control bits (WDTPW+WDTHOLD). 3. Use ORG assembly directive to set the program location counter of the current segment to the value of an expression that follows. Here ORG 0FF00h sets the location counter at the absolute address 0FF00h. This means that location counter is moved to this address. 4. Next, we allocate the string mystr that will start at the location 0FF00h using DB directive: mystr DB "HELLO WORLD, I AM THE MSP430!". As explained, this directive will allocate 30 bytes in memory starting at the address 0FF00h and initialize it with the string content. The content in memory will be as follows: 48 45 4c 4c 4f 20 57 4f 52 4c 44 2c 20 49 20 41 4d 20 54 48 45 20 4d 53 50 34 33 30 21 00. 5. How does my program execute on an MSP430? Upon powering-up the MSP430 control logic always generates a RESET interrupt request (it is the highest priority interrupt request). The value stored at the address 0xFFFE (the last word in the 64KB address space) is reserved to keep the starting address of the reset handler (interrupt service routine), and the first thing that the microcontroller does is to fetch the content from this address and put it in the program counter (PC, register R0). Thus, the starting address of our program should be stored at location 0xFFFE. Here, we move location counter to 0xFFFE and allocate 2 bytes (DC16 allocates 16 bits or two bytes) that will be initialized with the starting address of the main program. The starting address of the main program is marked by the label init. 6. RSEG is a segment control assembler directive that controls how code and data are located in memory. RSEG is used to mark the beginning of a relocatable code or data segment. CODE

and DATA are recognized segment types that are resolved by the linker. The IAR XLINK linker can recognize any other type of segment (e.g., CSTACK for code stack). 7. First instruction initializes the stack pointer register (MOV #SFE(CSTACK), SP). Our program does not use the stack, so we could have omitted RSEG CSTACK and this instruction. 8. The instruction MOV.W #WDTPW+WDTHOLD,&WDTCTL sets certain control bits of the watchdog timer control register (WDTCTL) to disable it. The watchdog timer by default is active upon reset, generating interrupt requests periodically. As this functionality is not needed in our program, we simply need to disable it. 9. Parallel ports in MSP430 microcontroller can be configured as input or output. A control register PxDIR determines whether the port x is input or output (we can configure each individual port pin). Our program drives all pins of the port P1, so it should be configured as the output (P1DIR=0xFF). Register R4 is loaded to point to the first character in the string. Register R5, the counter, is cleared before starting the main program loop. 10. The main loop starts at the gnext label. We use autoincrement addressing mode to read a new character (one byte) from the string (MOV.B @R4+, R6). The current character is kept in register R6. We compare the current character with the NULL character (CMP #0, R6). If it is the NULL character it is the end of the string and we exit the loop (JEQ lend). Pay attention that we used JEQ instruction? Why? If it is not the end of the string, we compare the current character with E. If there is no match we go back on the first instruction in the loop. Otherwise, we increase the value of the counter (register R5). 11. Finally, we move the lower byte from R5 to the parallel port 1, P1OUT=R5[7:0].

/*------------------------------------------------------------------- * Program : Counts the number of characters E in a string * Input : The input string is the mystr * Output : The port one displays the number of E's in the string * Written by : A. Milenkovic * Date : August 14, 2008 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *---------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file ORG 0FF00h mystr DB "HELLO WORLD, I AM THE MSP430!" ; the string is placed on the stack ; the null character is automatically added after the '!' NAME main ; module name PUBLIC main ; make the main label visible ; outside this module ORG 0FFFEh DC16 init ; set reset vector to 'init' label RSEG CSTACK ; pre-declaration of segment RSEG CODE ; place program in 'CODE' segment init: MOV #SFE(CSTACK), SP ; set up stack main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer BIS.B #0FFh,&P1DIR ; configure P1.x output MOV.W #mystr, R4 ; load the starting address of the string into the register R4 CLR.B R5 ; register R5 will serve as a counter gnext: MOV.B @R4+, R6 ; get a new character CMP #0,R6 JEQ lend ; go to the end CMP.B #'E',R6 JNE gnext INC R5 ; increment counter JMP gnext lend: MOV.B R5,&P1OUT ; Set all P1 pins BIS.W #LPM4,SR ; LPM4 NOP ; Required only for debugger END Figure 1. MSP430 Assembly Code for Count Character Program.

3. Creating an Application Project Please consult the tutorial on how to create a new workspace and project. Step 1. Choose Project>Create New Project. Select Empty project and save it as char_count. Step 2. Add the source file char_count.s43 to the project. Choose Project>Add Files. Step 3. Choose Project>Options and set all categories as explained in the Getting Starting With MSP430 IAR Embedded Workbench tutorial. Step 4. Select the source file char_count.s43 and compile it. (Choose Project>Compile). Click on the list file char_count.lst to see report generated by the compiler. Step 5. Link the program. Choose Project>Make. The application is ready for debugging. 4. Program Simulation and Debugging In this section we will discuss how to simulate program execution. Step 1: Go to Project>Options and select Debugger category. In the Driver box, choose Simulator (Figure 2). Click OK. Step 2: Choose Project>Debug. You will see the EW display as shown in Figure 3. Step 3: Step through the program step by step (use F11). Observe the Disassembly, Register View, and Memory View windows. Answer the following questions. What is the starting address of the program? How many clock cycles does each instruction take to execute? Observe the contents of memory location and registers as you step through the program. What is the content of the memory location at the address 0xFFFE? What are addresses of the special-purpose registers P1DIR and P1OUT? Monitor the contents of these locations as you walk through your program. Set breakpoints to move easier through your program. Step 4: Choose Stop Debugging.

Figure 2. Debugger category. Figure 3. IAR Simultor.

5. Assignments 1. Write an assembly program that will create a new output string by processing an input string. Each lower case letter character in the input string should be replaced by the corresponding upper case letter character. Assume that a string do not include more than one sentence. Assume the input string is welcome to Cpe323, yours MSP430!. Your program should create a new string WELCOME TO CPE323, YOURS MSP430! by processing the input string. Count the number of characters in the string and the number of changes. Set the port P1 to display the total number of characters, and port P2 to display the number of changes. 2. Write an assembly program that converts a string with four characters into an unsigned 16-bit integer. For example, a string A23F should be converted into an unsigned integer. Assume that the input string consists of only valid characters (0,... 9, A, B, C, D, E, F).