Tool/software: Code Composer Studio
I am writing a simple bit of code to use assembly to count words and sentences in a string. I have everything done, and my register counters work like they should. The problem I am having is that I want to put those counter values into variables "word" and "sent". I think I have declared the variables correctly, but I cannot find any info on the syntax I need to use to actually put the register count values into the variables I have created. Is there some syntax for the MOV instruction or maybe ADD instruction I can use to do this?
;code start
.cdecls C,LIST,"msp430.h" ; Include device header file
.def RESET ; Export program entry-point to
; make it known to linker.
myStr: .cstring "HELLO WORLD, I AM THE MSP430!"
.data
sent: .int 0 ; set sentence count variable and initialize to zero
word: .int 0 ; set word count variable and initialize to zero
.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 stack pointer
mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop
;-------------------------------------------------------------------------------
main: bis.b #0FFh,&P1DIR ; do not output the result on port pins
mov.w #myStr, R4 ; load the starting address of the string into R4
clr.b R5 ; register R5 will serve as a counter for words
clr.b R7 ; register R7 will serve as a counter for sentences
gnext: mov.b @R4+, R6 ; get a new character
cmp #0,R6 ; is it a null character
jeq lend ; if yes, go to the end
cmp.b #' ',R6 ; is it a ' ' character
jne pun1 ; if not, go to the next
inc.w R5 ; if yes, increment counter
mov R5,&word
jmp gnext ; go to the next character
pun1: cmp.b #'.',R6 ; is it a null character
jne pun2 ; if not, go to the next
inc.w R5 ; if yes, increment counter
inc.w R7 ; if yes, increment counter
jmp gnext ; go to the next character
pun2: cmp.b #'?',R6 ; is it a null character
jne pun3 ; if not, go to the next
inc.w R5 ; if yes, increment counter
inc.w R7 ; if yes, increment counter
jmp gnext ; go to the next character
pun3: cmp.b #'!',R6 ; is it a null character
jne gnext ; if not, go to the next
inc.w R5 ; if yes, increment counter
inc.w R7 ; if yes, increment counter
jmp gnext ; go to the next character
lend: mov.b 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
.end