/*------------------------------------------------------------------- * Program : Counts the length of a given string * Input : The input string is at hwstr * Output : P1 displays the length of the string * Written by : William K. Moore, III * Date : January 26, 2009 * Description : second 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 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 JMP gnext ; go back to the beginning of the loop lend: MOV.W #hwstr, R5 ; store the string address into R5 SUB.W R4, R5 ; R5 now contains the length of the string MOV.B R5, &P1OUT ; Set all P1 pins BIS.W #LPM4, SR ; LPM4 NOP ; Required only for debugger END