# 0.4 Lab 3-1 a "real-world" microprocessor: basic msp430 assembly

 Page 1 / 1
In this lab, students apply what they have learned to implement some basic assembly coding principals on real world hardware. They take what they know from the educational LC-3 and apply the basic principals to a new hardware situation.

## An intro to the msp430 from the lc-3

This week you will go over the basic differences between the MSP430's assembly ISA and the LC-3's, and learn how to write a basic assembly program for the MSP-430 using TI's Code Composer Studio. You have two main tasks ahead of you:

1. Following the ESCAPE platform labs 0 and 1, setup and establish communication with an ESCAPE sensor board. Run the test program to see if you can communicate wirelessly from the computer and if your sensors are working.
2. Coding in MSP430 Assembly, implement a Fibonacci sequence calculator . This should be done with a loop and run infinitely. Step through, explain, and demonstrate the code, using the CCS4 Debugger. Be sure to view the registers while stepping through the program. Observe the amount of CPU cycles each of the instructions takes to complete. Detailed Instructions

• ## The msp430 has a larger assembly instruction set than the lc-3

• MSP430 assembly includes some task specific instructions (Such as `inc` and `dec` ) to simplify reading the language
• Some MSP430 assembly instructions are interpreted instructions (Such as `pop` and `push` )
Interpreted Instructions
An instruction that is decomposed by the assembler into several smaller/ more basic fundamental instructions.
• ## Math and logical instructions are similar, but do not have a specific destination.

• MSP430 instructions come in two flavors, dual operand and single operand. Neither type has an explicit destination register, rather, the last operand serves as the destination too.
• For Example: `add R4, R5` in MSP430 assembly corresponds to `add R5, R4, R5` in LC-3
• Be careful to not overwrite data you wish to keep! If you need to preserve the values in both operand registers, you will need to save one of them first using a `mov` instruction.
• ## Msp430 supports some byte as well as word instructions

• Some MSP430 instructions allow you to address and write/read from a specific 8 bit byte in memory instead of the entire 16 bit word. The MSP430 memory has byte level addressability, but word instructions only operate on even numbered memory addresses (implicitly modifying the next odd numbered memory byte too). In many cases, especially when working with memory mapped I/O registers, you may need to operate on one specific byte only. To do so, just add a `.b` onto the end of the assembly instruction
• For example: `mov.b #0,&P1DIR` sets 8 bit length P1DIR register to zero without accidentally modifying the registers around it.
• MSP430 assembly specifies `.w` for executing word length instructions as well as `.b` for bit length instructions. The assembler by default assumes word length, so you the programmer don't have to explicitly write `mov.w R5, R14` although you should be conscious that `mov R5, R14` means the same thing.
• ## The msp430 has 16 cpu registers

• The MSP430 has twice as many CPU registers as the LC-3. Like in the LC-3 though, some of the MSP430's registers are reserved for the MSP430 runtime environment. Registers R0-R3 are reserved (Program Counter, Stack Pointer, Status Register, and a Constant Generation Register respectively), leaving registers R4 through R15 available for general purpose use as defined by the programmer.
• In your assembly programs you have 12 general purpose registers at your disposal, but you also must manage and keep track of the additional options.
• ## Indirect, relative, and absolute addressing occurs differently

• Instead of different indirect and direct load and store instructions ( `LD, LEA, LDI` , etc...), the MSP430 uses one versatile `mov` instruction with different operand addressing modes.
• `mov` can both read and write from memory-- it acts like both a load and store. ( `mov R4,&0x0200` corresponds to a `ST` while `mov&0x0200, R4` corresponds to a `LD` ) Be careful though, unlike in LC-3, `mov` does NOT update the condition register.
• Differentiate between the various direct and indirect modes by using special syntax to specify the type of operand you want. This allows you to mix addressing types (read indirect and store direct, etc...) even though everything is in one mov instruction.
• Direct register access: Rn (where n is the number of a general purpose register) Example: `R4` refers directly to R4
• Immediate Values: #x (where X is an immediate numerical value or label) Example: `#02h` refers to the literal hex number 2
• Indirect Access From a Register: @Rn (where n is the number of a general purpose register) Example: `@R6` refers indirectly to the data stored in the memory location in R6
• Indirect Offset Access: x(Rn) (where n is the number of a general purpose register and x is either an literal offset or a label) Example: `0(R7)` refers to the data stored in the location in memory pointed to by R7
This has the same end result as `@R7` . By TI code convention though, @Rn cannot be used to specify the destination of an operation, so if you wish to store a result indirectly, you must use the 0(Rn) syntax.
In this example R7 essentially contained the address while the literal offset was a small number. Offset Access can be very powerful when looked at the other way: where the literal contains a starting location in memory (potentially a label) and the register contains a small offset value incremented to access a series of locations in memory.
• You can also perform indirect or relative operand addressing with operations other than loads and stores

`add @R4, R5` takes the data stored in the address pointed to by R4 and adds it with R5, storing the result in R5.

• For more information, see the summary chart [link] or the comprehensive MSP430 users guide section 3.3.0 through 3.3.7
• ## The msp430 has two types of memory

• The MSP430 has both traditional RAM and non-volatile Flash memory. On a power reset, all values in RAM are cleared, so your program will be stored in Flash. The Flash write process is fairly involved, so we won't be writing to it in this class during run time (Code Composer will take care of loading your programs). In a nutshell, your program must store any temporary or changing values to RAM memory, although it can read your instructions and any preset constants from flash
• Important Memory Locations:
• 0x0200 : The Lowest Address in RAM
• 0x0280 : The Highest Address in RAM
• 0xF800 : The Beginning of Flash Memory
• 0xFFE0 : The Beginning of the Interrupt Vector Table

## The msp430 uses memory mapped i/o peripherals

• These devices function independently of the main processor, and use memory mapped registers to communicate with the program executing on the main CPU.
• Peripherals free up CPU resources and also allow more usage of low power CPU suspend modes. You'll learn more about peripherals in Lab 5

## Example code translations

LC-3 Assembly LC-3 Pseudocode MSP430 Assembly MSP430 Pseudocode
• `AND R4,R5,R6;`
• R4<- R5&R6
• `mov.w R5,R4;`
• `and.w R6,R4;`
• R4<- R5
• R4<- R4&R6
• `BRz R4,Loop;`
• if R4 == 0, branch to label "Loop"
• `tst R4;`
• `jz Loop;`
• load the attributes of R4 into the SR

## Other useful information

The code composer debugger actually runs on the real MSP430 hardware through a JTAG interface. To debug code, you have to have the launchpad board plugged into the computer .

The debugger controls the CPU's clock (and therefore can monitor it). To see how many clock cycles something takes, go to Target ->Clock ->Enable, and look in the bottom right corner of the screen for a small counter with a clock next to it.

## Part i assignment detail

Your task is to create a simple MSP430 assembly program using CCS4 and the MSP430 launchPad to calculate a Fibonacci sequence. You do not need to explicitly display the sequence, but rather use the Code Composer register view tools to watch the sequence progress as you step through your program.

To view the registers in Code Composer Studio v4, first start a debug session. Once you are in the debug perspective, you can go to View-->Registers to open the register dialog. From there, expand the section "Core Registers" to see your CPU registers, or the section "Port_1_2" to see the raw data from the input pins.

Enable the clock cycle monitor (Target-->Clock-->Enable) and you will see a yellow clock icon at the very bottom of your screen. This tells you how many actual CPU clock cycles have passed since you enabled it. Observe the different amounts of time that different instructions take.

The Fibonacci Sequence
The sequence of numbers starting with 0 , 1 in which N= (N-1) + (N-2)

0, 1, 1, 2, 3, 5, 8, 13, 21, 34...

The Fibonacci sequence plays an important role in the natural world. It appears in many biological sequences, and is fundamentally linked to the famed "golden ratio." For more "fun" info about Leonardo Fibonacci, see the ever reliable Wikipedia

Diagrams courtesy of TI document slau144e "MSP430 User's Guide"

The LC-3 was developed by Yale N. Patt (University of Texas at Austin) and Sanjay J. Patel (University of Illinois at Urbana-Champaign) and is used in their book Introduction to Computing Systems .

Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
for screen printed electrodes ?
SUYASH
What is lattice structure?
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!