/*------------------------------------------------------------------- * Program : Counts the number of E's in a given string * Input : The input string is at hwstr * Output : P1 displays the number of E's * Written by : William K. Moore, III * Date : January 26, 2009 * Description : first use of the msp430 assembler *---------------------------------------------------------------------*/ #include "msp430.h" ; #define controlled include file ORG 0FF00h hwstr DB "HELLO WORLD, I AM THE MSP430!" ; string is on the stack NAME main ; module name PUBLIC main ; make 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: MOV.W #WDTPW+WDTHOLD,&WDTCTL ; start of program, stop watchdog timer BIS.B #0FFh,&P1DIR ; configure P1 to be output MOV.W #hwstr, R4 ; load starting address of string into R4 CLR.B R5 ; R5 will serve as a counter gnext: MOV.B @R4+, R6 ; get next character CMP #0,R6 ; check for null character and end of processing JEQ lend ; we're done, go to end CMP.B #'E',R6 ; do we have an E? JNE gnext ; if not, go back to the beginning of the loop INC R5 ; increment counter JMP gnext ; just found an E, go back to the beginning of the loop lend: MOV.B R5,&P1OUT ; Set all P1 pins BIS.W #LPM4,SR ; LPM4 NOP ; Required only for debugger END