cpe323msp430_asmc - CPE 323 Introduction to Embedded...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CPE 323 Introduction to Embedded Computer Systems: MSP430: Assembly Language and C Instructor: Dr Aleksandar Milenkovic Lecture Notes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CPE 323 Intro2EmbeddedSystems 2 Outline ± Assembly Language Programming ± Adding two 32-bit numbers (decimal, integers) ± Counting characters ‘E’ ± Subroutines ± ± Subroutine Nesting ± Passing parameters ± Stack and Local Variables ± C and the MSP430
Background image of page 2
CPE 323 Intro2EmbeddedSystems 3 Assembly Language Programming: Decimal/Integer Addition of 32-bit Numbers ± Problem ± Write an assembly program that finds a sum of two 32-bit numbers ± Input numbers are decimal numbers (8-digit in length) ± Input numbers are signed integers in two’s complement ± Data: ± lint1: DC32 0x45678923 ± lint2: DC32 0x23456789 ± Decimal sum: 0x69135712 ± Integer sum: 0x68adf0ac ± Approach ± Input numbers: storage, placement in memory ± Results: storage (ABSOLUTE ASSEMBLER) ± Main program: initialization, program loops ± Decimal addition, integer addition
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CPE 323 Intro2EmbeddedSystems 4 Decimal/Integer Addition of 32-bit Numbers /*------------------------------------------------------------------------------ * Program : Program demonstrates addition of two operands lint1 and lint2. * Operands are first interpreted as 32-bit decimal numbers and * and their sum is stored into lsumd; * Next, the operands are interpreted as 32-bit signed integers * in two's complement and their sum is stored into lsumi. * Input : Input integers are lint1 and lint2 (constants in flash) * Output : Results are stored in lsumd (decimal sum) and lsumi (int sum) * Written by : A. Milenkovic * Date : September 10, 2008; Updated September 14, 2009 * Description: MSP430 IAR EW; Demonstration of the MSP430 assembler *-----------------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file NAME main ; module name PUBLIC main ; make the main label visible ; outside this module ORG 0xF000 ; move location pointer to 0xF000 lint1: DC32 0x45678923 ; operand1 lint2: DC32 0x23456789 ; operand2 ORG 0xFFFE DC16 main ; set reset vector to 'init' label ORG 0x0400 lsumd: DS32 1 ; allocates space for lsumd (2 words) lsumi: DS32 1 ; allocate space for lsumi (2 words)
Background image of page 4
CPE 323 Intro2EmbeddedSystems 5 Decimal/Integer Addition of 32-bit Numbers (cont’d) ORG 0xE000 ; starting address of the program main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #lint1, R4 ; pointer to lint1 MOV #lsumd, R8 ; pointer to lsumd (decimal sum) MOV #2, R5 ; R5 is a counter (2 words) CLR R10 ; clear R10 (used as a backup for SR) ldeca: MOV 4(R4), R7 ; load lint2 (@R4+4) into R7 MOV R10, R2 ; bring original R2 DADD @R4+, R7 ; decimal add to lint1 (@R4) MOV R2, R10 ; backup R2 in R10 MOV R7, 0(R8) ; store result back into lsumd ADD #2, R8 ; R8 points to the next word in lsumd DEC R5 ; decrement R5 JNZ ldeca ; jump if not zero to ldeca
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CPE 323 Intro2EmbeddedSystems 6 Decimal/Integer Addition of 32-bit Numbers
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/04/2011 for the course CPE 323 taught by Professor Milenkovic during the Spring '10 term at University of Alabama - Huntsville.

Page1 / 58

cpe323msp430_asmc - CPE 323 Introduction to Embedded...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online