You are on page 1of 8

MSP430 LAB programs

2012

MSP430
MSP430 ARCHITECTURE

Large 16-bit register file eliminates single accumulator bottleneck High-bandwidth 16-bit data and address bus with no paging RISC architecture with 27 instructions and 7 addressing modes Single-cycle register operations with full-access Direct memory-memory transfer designed for modern programming Compact silicon 30% smaller than an 8051 saves power and cost

ECE DEPARTMENT

NARENDRAKUMAR

Page 1

MSP430 LAB programs

2012

INSTRUCTIONSET

ECE DEPARTMENT

NARENDRAKUMAR

Page 2

MSP430 LAB programs

2012

MEMORY MODEL

ECE DEPARTMENT

NARENDRAKUMAR

Page 3

MSP430 LAB programs

2012

IAR PROGRAMS Steps 1.create new project-asm-project name ok 2.new workspace--new file filename 3.save file save workspace- make(F7)rebuild alldownload and debug 4.step over or run cursor or Run completely
NOTE: use valid signed numbers to store the data in memory locations (up to 7Fh)
BLOCK MOVE Write an ALP to move a block of 10-bytes from location X to location Y. The block length N is stored in R6 register. X=2000h and Y=2020h main: MOV #2000h,R4 MOV #2020h,R5 MOV #10, R6 NEXT: MOV.B @R4,0(R5) INC R4 INC R5 DEC R6 JNZ NEXT JMP $ END ;INITIALIZE SOURCE POINTER ; INITIALIZE DESTINATION POINTER ; INITIALIZE COUNTER ;MOVE A BYTE OF DATA FROM SOURCE TO DESTINATION ; INCREMENT SOURCE address ;INCREMENT DESTINATION address ; DECREMENT COUNTER ; REPEAT TILL COUNTER IS ZERO ; HALT

BLOCK EXCHANGE Write an ALP to exchange 10-bytes from location X to location Y. The block length N is stored in R6 register. X=2000h and Y=2020h main MOV #2000h,R4 MOV #2020h,R5 MOV #10, R6 NEXT: MOV.B @R4,R7 MOV.B @R5,0(R4) MOV.B R7,0(R5) INC R4 INC R5 ;ARRAY1 POINTER ; ARRAY2 POINTER ;COUNTER ;GET DATA BYTE FROM ARRAY1 INTO R7 ;MOVE DATA BYTE FROM ARRAY2 TO ARRAY1 ;STORE R7 CONTENTS(ARRAY1 DATA) INTO ARRAY2 ;POINT TO NEXT BYTE IN ARRAY1 ;POINT TO NEXT BYTE IN ARRAY2

ECE DEPARTMENT

NARENDRAKUMAR

Page 4

MSP430 LAB programs

2012

DEC.B R6 JNZ NEXT JMP $ END

;DECREMENT COUNTER ; REPEAT TILL ZERO

BUBBLE SORT( descending order) Write an assembly language program to sort an array of N= 5 bytes of data in descending order stored from location 3000h.(use bubble sort algorithm). main: MOV #4,R7; N-1 comparisons and N-1 iterations NEXT: MOV #3000H,R4;starting address of the array pointed by R4 MOV #3001H,R5; Next address of the array pointed by R5 MOV.B R7, R6;load the value for N-1 comparisons BACK: CMP.B @R5,0(R4);compare the contents of memory locations pointed by R4and R5 JGE NO_EXCH;if the result is greater or equal then jump to no exchange MOV.B @R4,R8; otherwise exchange the contents. MOV.B @R5,0(R4) MOV.B R8,0(R5) NO_EXCH: INC R4 INC R5 DEC R6 JNZ BACK; go to next comparison DEC R7 JNZ NEXT; go to next iteration. JMP $ END Write an assembly language program to sort an array of N= 5 bytes of data in ascending order stored from location 3000h.(use bubble sort algorithm). (ascending order) main: MOV #4,R7; N-1 NEXT: MOV #3000H,R4 MOV #3001H,R5 MOV.B R7, R6 BACK: CMP.B @R4,0(R5); JGE NO_EXCH MOV.B @R4,R8 MOV.B @R5,0(R4); MOV.B R8,0(R5) NO_EXCH: INC R4 INC R5 DEC R6 JNZ BACK DEC R7 JNZ NEXT JMP $ ECE DEPARTMENT NARENDRAKUMAR Page 5

MSP430 LAB programs

2012

END Find the largest number Write an assembly language program to find the largest number in the given array stored from location 3000h. main: MOV #9,R6 MOV.B #00,R8 MOV #4000H,R4 BACK: CMP.B @R4, R8; JGE L1 MOV.B @R4,R8 L1: INC R4 DEC R6 JNZ BACK INC R4 MOV.B R8,0(R4) JMP $ END Find the smallest of the number. Write an assembly language program to find the largest number in the given array stored from location 3000h. main: MOV #9,R6 MOV #4000H,R4 MOV.B @R4,R8 BACK: CMP.B R8,0(R4); JGE L1 MOV.B @R4,R8 L1: INC R4 DEC R6 JNZ BACK INC R4 MOV.B R8,0(R4) JMP $ END ASCII TO BINARY CONVERSION Write an ALP to convert an ASCII code to Binary. The given ASCII code stored at 40h and the converted binary number has to be stored at 42h. main: MOV #40H, R4 ; MOV.B @R4+, R6 CMP # 41H,R6 JGE L1 ; SUB #30H, R6 ECE DEPARTMENT

; ; ; NARENDRAKUMAR Page 6

MSP430 LAB programs

2012

JMP L2 L1: SUB #37H, R6 L2: INC R4 MOV.B R6,0(R4) JMP $ END

BINARY TO ASCII CONVERSION Write an ALP to convert a binary code to ASCII. The given binary code stored at 30h and the converted binary number has to be stored at 32h. main: MOV #30H, R5 ; MOV.B @R5+, R6 CMP # 0AH,R6 JGE L1 ; ADD #30H, R6 JMP L2 L1: ADD #37H, R6 ; L2: INC R5 MOV.B R6,0(R5) JMP $

; ; ;

ADDITION OF TWO 16-bit NUMBERS main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer CLR R5 MOV.W #2000h,R4 ; moving data from 2000address to R4 register MOV.W #2002h,R6 ; moving data from 2002 address to R6 register ADD.W @R4,0(R6) JM P $ ; jump to current location '$' End MULTIPLICATION OF TWO 16-bit NUMBERS main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #3000h,R5 MOV @R5,R4 ; moving data 1 to R4 INCD R5 MOV @R5,R9 ; moving data 2 to R9 MOV #0000,R8 MOV.W R4,R6 ; moving data 1 to R6 SUB.W #0001,R6;subtract 1 from R6 MOV.W R9,R7; moving data 2 to R7 L1: ADD.W R7,R9 JNC L2

ECE DEPARTMENT

NARENDRAKUMAR

Page 7

MSP430 LAB programs

2012

ADD #0001,R8 ;store if carry is generated in R8 L2: DEC.W R6 JNZ L1;repetitive addition until R6=0 INCD R5 MOV.W R8,0(R5);store result INCD R5 MOV.W R9,0(R5) ; result saved in the 0x3030 address JMP $ ; jump to current location '$' ; (endless loop) END

ECE DEPARTMENT

NARENDRAKUMAR

Page 8

You might also like