The MSP430 is a tiny, lightweight, embedded processor with 64K of addressable RAM and a clock of 8-16Mhz. It is roughly equivalent to a Sega Genesis processor spec wise.
I will comment the hell out of my programs and offer any information to anybody interested. You can also download a simulator/emulator and IDE (and write/run my code or write your own) for the MSP430 from Texas Instrument's website: http://focus.ti.com/docs/toolsw/folders ... start.html
I was given roughly two weeks to complete this assignment, but being the lazy ass that I am, I put it off until the day before it was due. It took me about 2 hours to complete.
I think assembly programming is a great way to expand your programming skills. It forces you to think outside of the strictly C++ way that your brain has adapted to solving problems. I always feel smarter after writing something in ASM.
Code: Select all
/*
Falco Girgis
CPE323 Lab Section 2
Project #2
Program takes a string "inStr" and creates "outStr" which lowercases
every letter that isn't the first letter in the sentence. The total number
of characters in inStr are written to port P1, and the total number of
changed characters are outputted to port P2.
inStr - allocated somewhere in RAM
outStr - starts at byte following inStr in RAM
R4 - pointer to current character in inStr
R5 - pointer to current address of outStr
R6 - current character
R7 - beginning of sentence flag
R14 - counter for total number of characters
R15 - counter for total number of changes
*/
#include "msp430.h"
NAME main ; module name
PUBLIC main ; make main accessible from outside module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment CSTACK
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; initialize stack
main: NOP ; main entry point
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer
BIS.B #0FFh,&P1DIR ; configure P1.x output
BIS.B #0FFh,&P2DIR ; configure P2.x output
MOV #inStr, R4 ; move start addr of inStr to R4
MOV #outStr, R5 ; move start addr of outStr to R5
CLR R14 ; clear character counter
CLR R15 ; clear change counter
CLR R7 ; clear "beginning of sentence" flag
gchar: MOV.B @R4+, R6 ; put char in R6 and increase string pointer
CMP #0,R6 ; check if curChar is null
JEQ done ; if so, jump to done
INC R14 ; add one to character count
; CHECK LOWER - checks if things are NOT lowercase letters
chklwr: CMP #'[', R6 ; Upper bound of lowercase letter
JGE chkPnc ; not in range, check if punctuation.
CMP #'A', R6 ; lower bound of lowercase letter
JL chkPnc ; not in range, check if punctuation
CMP.B #1, R14 ; check if first char in string
JEQ noPunc ; if yes, skip this letter
CMP.B #1, R7 ; check if beginning of sentence
JEQ noPunc ; if yes, skip this letter
; TO LOWER - sets curChar to be a lowercase letter
tolowr:
ADD #32, R6 ; add the ascii offset to uppercase letter
INC R15 ; increment change counter
; OUT CHAR - Outputs character
outCh: MOV.B R6, 0(R5) ; write curChar to RAM
INC R5 ; increment outStr pointer
JMP gchar ; get next character
punct: MOV #1, R7 ; set beginning of sentence flag
JMP outCh ; output character
noPunc: CLR R7; ; clear flag
JMP outCh; ; output character
chkPnc: CMP.B #'!', R6 ; check if char == '!'
JEQ punct ; if yes, get next char
CMP.B #'.', R6 ; check if char == '.'
JEQ punct ; if yes, get next char
JMP outCh
done:
MOV.B 0, R5 ; append NULL to outStr
MOV.B R14, &P1OUT ; store total number of characters
MOV.B R15, &P2OUT ; store total number of changes
JMP $ ; jump to itself so that the program NEVER STOPS EXECUTING AND IDLES
inStr DB "WELCOME to Cpe323. YOURS MSP430!!!!.. SUCK. ME. RAAAwwwW.W" ; the string is placed on the stack
outStr DB 0 ; define the starting address for our outStr
END