Sunteți pe pagina 1din 7

Internal to internal data block move -byte #include "msp430.

h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #0x20,R4 ;Initialize source pointer MOV #0x40,R5 ; Initialize destination pointer MOV.B #10, R6 ; Initialize counter NEXT: MOV.B 0(R4),0(R5) ;Move a byte of data from source to destination INC R4 ; Increment source pointer once (byte transfer) INC R5 ;Increment destination pointer DEC.B R6 ; Decrement Counter JNZ NEXT ; Repeat till counter is zero JMP $ END Internal to Internal data move-word #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack ; jump to current location '$' ; (endless loop)

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD, &WDTCTL ; Stop watchdog timer MOV #0x20,R4 MOV #0x40,R5 MOV.B #10, R6 NEXT: MOV 0(R4),0(R5) INCD R4 INCD R5 DEC.B R6 JNZ NEXT JMP $ ; jump to current location '$' END

Arthimatic and logic operations #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label visible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #0X20, R4 ;pointer to 1st number MOV.B @R4+, R5 ; R5 = 1st number & R4 points to 2nd number MOV.B @R4+, R6 ; R6 = 2nd number & R4 points to add result location MOV.B R6, 0(R4) ;move 2nd num to result location and ADD.B R5, 0(R4) ;add to the result location the 1st number INC R4 ;point to next result location (to store the result of next operation) MOV.B R6, 0(R4) DADD.B R5, 0(R4) ;decimal add INC R4 MOV.B R6, 0(R4) SUB.B R5, 0(R4) ;subtract

INC R4 MOV.B R6, 0(R4) AND.B R5, 0(R4) INC R4 MOV.B R6, 0(R4) BIS.B R5, 0(R4) INC R4 MOV.B R6, 0(R4) XOR.B R5, 0(R4) INC R4 JMP $ END upCounter by using port #include "msp430.h" NAME main

;AND ; OR operation ;EX-OR operation

; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD, &WDTCTL ; Stop watchdog timer MOV.B #0xFF,&P2DIR ;set up PORT2 as output port MOV.B #0x00,R4 ;Initialize count as 00 for upcount NEXT: INC.B R4 ; Increment for next count MOV.W #0x02,R5 DELAY: DEC.W R5 JNZ DELAY MOV.B R4, &P2OUT JMP NEXT END ;set up a small delay

;send the count to port2 ; (endless loop)

Ascii to decimal #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD, &WDTCTL ; Stop watchdog timer MOV #0x050, R4 ; R4 has address 50H (remember 50h has the ASCII number to be converted) MOV.B @R4+, R6 ; Get data pointed by R4 into register R6. At the same time increment R4 to point to next location i.e., 51h SUB.B #0x30,R6 ; subtract 30h from R6 CMP # 0x0A,R6 ; Check if contents of R6 are greater than 0Ah JNC SKIP ; jump to skip if R6 contents < 0A SUB #0x07, R6 ; if R6 > 0A, subtract 07 further SKIP: MOV.B R6, 0(R4) ; Store the converted data in memory location (51h) pointed by R4 JMP $ ; Terminate the program by Jumping to infinite loop END Sorting program #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG CSTACK CODE

init: MOV

#SFE(CSTACK), SP

; set up stack

main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV.B #05, R5 ; n-1 = 5 ,i.e., length of array into pass counter OUTER: MOV #0x20,R4 ;starting address of array MOV.B R5,R6 ;load exchange counter for inner pass INNER: MOV.B @R4+,R7 ;current number into R7 & array pointer updated to next number CMP.B @R4,R7 ;compare the consecutive numbers JNC SKIP ; if current number less than next number, skip the exchange ;the code below exchanges the two numbers in the array MOV.B @R4,R8 MOV.B R7,0(R4) DEC R4 MOV.B R8,0(R4) INC R4 SKIP: DEC.B R6 JNZ INNER DEC.B R5 JNZ OUTER JMP $ END ; Decrement the exchange counter in the inner pass ; Decrement number of passes

Exchange Data between two memorys locations #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #0x20,R4 ;Array1 pointer MOV #0x30,R5 ; Array2 pointer

MOV.B #05, R6 NEXT: MOV.B @R4,R7 MOV.B @R5,0(R4) MOV.B R7,0(R5) INC R4 INC R5 DEC.B R6 JNZ NEXT JMP $ END

;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 ;Decrement counter ; Repeat till zero

Moving data in same address location #include "msp430.h" NAME main ; #define controlled include file ; module name ; make the main label vissible ; outside this module ; set reset vector to 'init' label ; pre-declaration of segment ; place program in 'CODE' segment ; set up stack

PUBLIC main ORG 0FFFEh DC16 init RSEG RSEG init: MOV CSTACK CODE

#SFE(CSTACK), SP

main: NOP ; main program MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer MOV #0x29, R4 ;End address of source string=start address + n MOV #0x2E,R5 ;End address of destination string MOV.B #10, R6 NEXT: MOV.B 0(R4),0(R5) DEC R4 DEC R5 DEC.B R6 JNZ NEXT JMP $ END

S-ar putea să vă placă și