Wednesday, November 3, 2010

My assembly code to implement 'strcpy' and 'strcmp' in MSP430

         Here i am trying to implement 'strcpy' any 'strsmp' functions defined in KandR. First i am creating a dummy C code just containing main() and opening and closing braces and compiling the C code with -S option for creating the assembly code.
$msp430-gcc -mmcu=msp430x2013 filename.c -S
      Now we get a assembly code file with same filename as that of the c file with a change in extension as .s
       After inserting all the necessary assembly code to the.s file we can create the a.out file using
$msp430-gcc -mmcu=msp430x2013 filename.s

1.Strcpy

         First of all i am clearing the register r7 and after completing the copy r7 is set. This is for showing the completion of the process. Now i am moving an address of RAM  (0x200) to r5 which is the source and another address of RAM (0x210) to r6 which is the destination. Now we can start the loop with a testing that the value at memory location specified in r5 is 0 or not. If it is not zero then move the value at address specified in r5 to the address specified in r6.  Then increment r5 and r6 values (addresses). Else move zero to the memory location specified in r6 and move 1 to r7 for indicating the completion.

2.Strcmp


         Here if the compare fails then red LED blinks. R8 have the same role of r7 in strcpy. By moving 1 to the address 0x022 makes the pin 1 for output mode. 0x022 is address of P1DIR. Then i am moving the value 0 to the address 0x021 making the pin1 disabled. Now i am moving an address of RAM  (0x200) to r5 which is the source and another address of RAM (0x210) to r6 which is the destination. Now we can start the loop with a comparing that the value at memory location specified in r5 is equal to the value at memory location specified in r6 or not. If it is equal then check whether the value at address specified in r5 is equal to 0 or not. If not equal to zero then we can increment r5 and r6 or else we can move to the last step move the value at address specified in r7 to r8. If the first compare fails then move a value 1 to the address specified in r7 which blinks the red LED indicating that compare returns non-zero value.

No comments:

Post a Comment