;------------------------------------------------------------------------------- ; 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 "6*8" ; define string ;------------------------------------------------------------------------------- .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 ; Use R5 to hold the character clr.b R6 ; use r6 for first number clr.b R7 ; use R7 for second mov.b #0, R3 ; use r3 as counter mov.b @R4+, R5 ; get a new character cmp.b #58, R5 ; check for ':' character jge error ; if equal or greater, jump to error cmp.b #48, R5 ; is it a '0' jl error ; if less, jump to error mov.b R4, R6 ; move first number into Register 6 mov.b @R4+, R5 ; get a new character cmp #'*', R5 ; is it '*' jne error ; if not equal, jump to error mov.b @R4+, R5 ; get next character cmp.b #58, R5 ; check for ':' character jge error ; if equal or greater, jump to error cmp.b #48, R5 ; is it a '0' jl error ; if less, jump to error mov.b @R4+, R5 ; get next char cmp.b #0, R5 ; is it NULL jne error ; error if not mov.b R4, R7 ; move next number to register 7 cmp.b R7, R5 ; which is less jge firstNum ; if first is greater jump to firstNum jl secondNum ; less than, jump to secondNum firstNum: cmp R3, R5 ; comparing r3 to loop top jz endOne ; when 0 end loop dadd.b R7, R7 ; add bigger number to itself dadd.b r3,r3 ; increment counter jmp firstNum ; jump to firstNum secondNum: cmp R3, R7 ; comparing r3 to loop top jz endTwo ; when 0 end loop dadd.b R5, R5 ; add bigger number to itself dadd.b r3,r3 ; increment counter jmp secondNum ; jump to secondNum error: mov #0xFF, &P2OUT ; move FF to P2OUT jmp errorEnd endOne: mov.w R7,&P2OUT ; Write result in P1OUT (not visible on port pins) endTwo: mov.w R5,&P2OUT ; Write result in P1OUT (not visible on port pins) errorEnd: 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