sadf

Dependencies:   mbed

Committer:
armorris2001
Date:
Thu Oct 29 00:45:39 2015 +0000
Revision:
0:b7eda4fdb627
e ryas

Who changed what in which revision?

UserRevisionLine numberNew contents of line
armorris2001 0:b7eda4fdb627 1 #include "mbed.h"
armorris2001 0:b7eda4fdb627 2
armorris2001 0:b7eda4fdb627 3 __asm void my_strcpy(const char *src, char *dst);
armorris2001 0:b7eda4fdb627 4 __asm void my_capitalize(char *str);
armorris2001 0:b7eda4fdb627 5
armorris2001 0:b7eda4fdb627 6 int main(void){
armorris2001 0:b7eda4fdb627 7 const char a[] = "Hello World!";
armorris2001 0:b7eda4fdb627 8 char b[20];
armorris2001 0:b7eda4fdb627 9
armorris2001 0:b7eda4fdb627 10 my_strcpy(a,b);
armorris2001 0:b7eda4fdb627 11 my_capitalize(b);
armorris2001 0:b7eda4fdb627 12
armorris2001 0:b7eda4fdb627 13 while(1)
armorris2001 0:b7eda4fdb627 14 ;
armorris2001 0:b7eda4fdb627 15 }
armorris2001 0:b7eda4fdb627 16
armorris2001 0:b7eda4fdb627 17 __asm void my_strcpy(const char *src, char *dst){
armorris2001 0:b7eda4fdb627 18 loop
armorris2001 0:b7eda4fdb627 19 LDRB r2, [r0] ; Load byte into r2 from memory, pointed to by r0 (src pointer)
armorris2001 0:b7eda4fdb627 20 ADDS r0, #1 ; Increment src pointer
armorris2001 0:b7eda4fdb627 21 STRB r2, [r1] ; Store byte in r2 into memory pointed to by (dst pointer)
armorris2001 0:b7eda4fdb627 22 ADDS r1, #1 ; Increment dst pointer
armorris2001 0:b7eda4fdb627 23 CMP r2, #0 ; What the byte == 0?
armorris2001 0:b7eda4fdb627 24 BNE loop ; If not, repeat the loop
armorris2001 0:b7eda4fdb627 25 BX lr ; Else return from subroutine
armorris2001 0:b7eda4fdb627 26 }
armorris2001 0:b7eda4fdb627 27
armorris2001 0:b7eda4fdb627 28 __asm void my_capitalize(char *str){
armorris2001 0:b7eda4fdb627 29 cap_loop
armorris2001 0:b7eda4fdb627 30 LDRB r1, [r0] ; Load byte into r1 from memory pointed to by r0 (str pointer)
armorris2001 0:b7eda4fdb627 31 CMP r1, #'a'-1 ; Compare byte with the character before 'a'
armorris2001 0:b7eda4fdb627 32 BLS cap_skip ; If byte is lower or same, then skip this byte
armorris2001 0:b7eda4fdb627 33
armorris2001 0:b7eda4fdb627 34 CMP r1, #'z' ; Compare it with the 'z' character
armorris2001 0:b7eda4fdb627 35 BHI cap_skip ; If it is higher, then skip this byte
armorris2001 0:b7eda4fdb627 36
armorris2001 0:b7eda4fdb627 37 SUBS r1, #32 ; Else subtract out difference to capitalize it
armorris2001 0:b7eda4fdb627 38 STRB r1, [r0] ; Store the capitalized byte back in memory
armorris2001 0:b7eda4fdb627 39
armorris2001 0:b7eda4fdb627 40 cap_skip
armorris2001 0:b7eda4fdb627 41 ADDS r0, r0, #1 ; Increment str pointer
armorris2001 0:b7eda4fdb627 42 CMP r1, #0 ; Was the byte 0?
armorris2001 0:b7eda4fdb627 43 BNE cap_loop ; IF not, repeat the loop
armorris2001 0:b7eda4fdb627 44 BX lr ; Else return from subroutine
armorris2001 0:b7eda4fdb627 45 }