cancel
Showing results for 
Search instead for 
Did you mean: 

Hi I am beginning using STM32CUbe IDE and I ant to migrate a Keil uBision project where I have a code calling two ASM functions.

HMero.1
Associate II

these are the functions

__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 ; Was 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 it 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

}

The GNU compiler doesnt accept these functions

Please can you tell how to change these functions?

Best regards and thanks in advance

Horacio Merovich

1 ACCEPTED SOLUTION

Accepted Solutions

Honestly I despair the state of post-secondary education... is there not someone qualified to lead the course?

/* GNU/GAS Assembler code added into startup.s */
 
/* extern void my_strcpy(const char *src, char *dst); note parameters backward compared to C */
 
  .section  .text.my_strcpy
  .type  my_strcpy, %function
 
my_strcpy:
 
loop:
 
  LDRB r2, [r0]   /* Load byte into r2 from memory pointed to by r0 (src pointer) */
  ADD  r0, #1     /* Increment src pointer */
 
  STRB r2, [r1]   /* Store byte in r2 into memory pointed to by (dst pointer) */
  ADD  r1, #1     /* Increment dst pointer */
 
  CMP  r2, #0     /* Was the byte 0? */
  BNE  loop       /* If not, repeat the loop */
 
  BX   lr         /* Else return from subroutine */
 
.size  my_strcpy, .-my_strcpy
 
 
/* extern void my_capitalize(char *str); */
 
  .section  .text.my_capitalize
  .type  my_capitalize, %function
 
my_capitalize:
 
cap_loop:
 
  LDRB r1, [r0]   /* Load byte into r1 from memory pointed to by r0 (str pointer) */
  CMP  r1, #'a'-1 /* compare it 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 */
 
  SUB  r1,#32     /* Else subtract out difference to capitalize it  */
  STRB r1, [r0]   /* Store the capitalized byte back in memory */
 
cap_skip:
 
  ADD  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 */
 
.size  my_capitalize, .-my_capitalize
 
/* ... */

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

Start by replacing this with standard C library functions, strcpy (or better strncpy) and strupr.

Optimize later, when the project is working.

-- pa

HMero.1
Associate II

Thanks for your answer

This code is part of a ARM Assembler course so we dont want to use here the standard C library functions.

Best regards

Honestly I despair the state of post-secondary education... is there not someone qualified to lead the course?

/* GNU/GAS Assembler code added into startup.s */
 
/* extern void my_strcpy(const char *src, char *dst); note parameters backward compared to C */
 
  .section  .text.my_strcpy
  .type  my_strcpy, %function
 
my_strcpy:
 
loop:
 
  LDRB r2, [r0]   /* Load byte into r2 from memory pointed to by r0 (src pointer) */
  ADD  r0, #1     /* Increment src pointer */
 
  STRB r2, [r1]   /* Store byte in r2 into memory pointed to by (dst pointer) */
  ADD  r1, #1     /* Increment dst pointer */
 
  CMP  r2, #0     /* Was the byte 0? */
  BNE  loop       /* If not, repeat the loop */
 
  BX   lr         /* Else return from subroutine */
 
.size  my_strcpy, .-my_strcpy
 
 
/* extern void my_capitalize(char *str); */
 
  .section  .text.my_capitalize
  .type  my_capitalize, %function
 
my_capitalize:
 
cap_loop:
 
  LDRB r1, [r0]   /* Load byte into r1 from memory pointed to by r0 (str pointer) */
  CMP  r1, #'a'-1 /* compare it 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 */
 
  SUB  r1,#32     /* Else subtract out difference to capitalize it  */
  STRB r1, [r0]   /* Store the capitalized byte back in memory */
 
cap_skip:
 
  ADD  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 */
 
.size  my_capitalize, .-my_capitalize
 
/* ... */

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HMero.1
Associate II

Hi

Thanks for your contribution to improve our education.

Best regards

Horacio