sadf

Dependencies:   mbed

main.c

Committer:
armorris2001
Date:
2015-10-29
Revision:
0:b7eda4fdb627

File content as of revision 0:b7eda4fdb627:

#include "mbed.h"

__asm void my_strcpy(const char *src, char *dst);
__asm void my_capitalize(char *str);

int main(void){
    const char a[] = "Hello World!";
    char b[20];
    
    my_strcpy(a,b);
    my_capitalize(b);
    
    while(1)
    ;    
}

__asm void my_strcpy(const char *src, char *dst){
loop
    LDRB r2, [r0]   ; Load byte into r2 from memory, pointed to by r0 (src pointer)
    ADDS r0, #1     ; Increment src pointer
    STRB r2, [r1]   ; Store byte in r2 into memory pointed to by (dst pointer)
    ADDS r1, #1     ; Increment dst pointer
    CMP r2, #0      ; What the byte == 0?
    BNE loop        ; If not, repeat the loop
    BX lr           ; Else return from subroutine    
}

__asm void my_capitalize(char *str){
cap_loop
    LDRB r1, [r0]   ; Load byte into r1 from memory pointed to by r0 (str pointer)
    CMP r1, #'a'-1  ; Compare byte with the character before 'a'
    BLS cap_skip    ; If byte is lower or same, then skip this byte
    
    CMP r1, #'z'    ; Compare it with the 'z' character
    BHI cap_skip    ; If it is higher, then skip this byte
    
    SUBS r1, #32    ; Else subtract out difference to capitalize it
    STRB r1, [r0]   ; Store the capitalized byte back in memory

cap_skip
    ADDS r0, r0, #1 ; Increment str pointer
    CMP r1, #0      ; Was the byte 0?
    BNE cap_loop    ; IF not, repeat the loop
    BX lr           ; Else return from subroutine
}