sadf

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.c Source File

main.c

00001 #include "mbed.h"
00002 
00003 __asm void my_strcpy(const char *src, char *dst);
00004 __asm void my_capitalize(char *str);
00005 
00006 int main(void){
00007     const char a[] = "Hello World!";
00008     char b[20];
00009     
00010     my_strcpy(a,b);
00011     my_capitalize(b);
00012     
00013     while(1)
00014     ;    
00015 }
00016 
00017 __asm void my_strcpy(const char *src, char *dst){
00018 loop
00019     LDRB r2, [r0]   ; Load byte into r2 from memory, pointed to by r0 (src pointer)
00020     ADDS r0, #1     ; Increment src pointer
00021     STRB r2, [r1]   ; Store byte in r2 into memory pointed to by (dst pointer)
00022     ADDS r1, #1     ; Increment dst pointer
00023     CMP r2, #0      ; What the byte == 0?
00024     BNE loop        ; If not, repeat the loop
00025     BX lr           ; Else return from subroutine    
00026 }
00027 
00028 __asm void my_capitalize(char *str){
00029 cap_loop
00030     LDRB r1, [r0]   ; Load byte into r1 from memory pointed to by r0 (str pointer)
00031     CMP r1, #'a'-1  ; Compare byte with the character before 'a'
00032     BLS cap_skip    ; If byte is lower or same, then skip this byte
00033     
00034     CMP r1, #'z'    ; Compare it with the 'z' character
00035     BHI cap_skip    ; If it is higher, then skip this byte
00036     
00037     SUBS r1, #32    ; Else subtract out difference to capitalize it
00038     STRB r1, [r0]   ; Store the capitalized byte back in memory
00039 
00040 cap_skip
00041     ADDS r0, r0, #1 ; Increment str pointer
00042     CMP r1, #0      ; Was the byte 0?
00043     BNE cap_loop    ; IF not, repeat the loop
00044     BX lr           ; Else return from subroutine
00045 }