;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with TI Code Composer Studio ; ; ;------------------------------------------------------------------------------- .cdecls C,LIST,"msp430.h" ; Include device header file ;------------------------------------------------------------------------------- .def RESET ; Export program entry-point to ; make it known to linker. ;------------------------------------------------------------------------------- .data myStr: .cstring "!#$%&()*+,-./:;<=>?@[\\]^_`{|}~" ; Define cstring variable symb_count: .int 0 ; counter variable .text ; Assemble into program memory. .retain ; Override ELF conditional linking ; and retain current section. .retainrefs ; And retain any sections that have ; references to current section. ;------------------------------------------------------------------------------- RESET mov.w #__STACK_END,SP ; Initialize stackpointer StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer ;------------------------------------------------------------------------------- ; Main loop here ;------------------------------------------------------------------------------- main: mov.w #myStr, R4 ; Move the starting address of myStr into register 4 clr.b R5 ; Register 5 will serve as a counter gnext: mov.b @R4+, R6 ; get a new character cmp.b #0, R6 ; check for null character jeq lend ; if null, go to end cmp.b #97, R6 ; check if 'a' jeq gnext ; if equal, get next character jge range2 ; if greater or equal, jump to range2 jl capitals ; if less than, jump to numbers label range2: cmp.b #123, R6 ; is it '{' char jge incr ; if it is, jump to incr jl gnext ; if less than, get next character capitals: cmp.b #91, R6 ; is it '[' jge incr ; if it is or greater, jump to incr cmp.b #65, R6 ; is it 'A' jge gnext ; if equal or greater, get next character cmp.b #58, R6 ; is it ';' jge incr ; if greater or equal, jump to incr cmp.b #48, R6 ; is it '0' jge gnext ; if equal or greater, get next character incr: inc.w R5 ; increment counter jmp gnext ; get next character lend: mov.w R5,&P1OUT ; Write result in P1OUT (not visible on port pins) bis.w #LPM4, SR ; LPM4 nop ; Required only for debugger ;------------------------------------------------------------------------------- ; Stack Pointer definition ;------------------------------------------------------------------------------- .global __STACK_END .sect .stack ;------------------------------------------------------------------------------- ; Interrupt Vectors ;------------------------------------------------------------------------------- .sect ".reset" ; MSP430 RESET Vector .short RESET