C   69

inv

Guest on 2nd July 2022 04:34:11 PM

  1. #include <avr/io.h>
  2. #include <avr/pgmspace.h> // library to handle data in the program area
  3. int strlen(char *); // just so the compiler doesn't issue warnings!
  4. char mystring[] PROGMEM="ABCDEFGHI"; // define a C string in the program area
  5. char buffer[20] __attribute__((section("*.noinit"))); // __attribute__((section("*.noinit"))); // when we don't want to initialize global variable;
  6. register unsigned char temp asm("r2"); // did not change code size = 158 bytes
  7.  
  8. int main(){
  9.     char *i, *f;
  10.     strcpy_P(buffer, mystring); // copy string to RAM
  11.         i=buffer; // pointer to start of chain
  12.         f= buffer + strlen(buffer); //points to the end of the string + 1
  13.         while (i < f ){ // walk the vector while i < f
  14.                 temp= *--f; // predecrement f, save last byte in temp
  15.                 *f = *i; // put the value of the first in the last byte
  16.                 *i++= temp; // now in the first I put the saved value and increment i
  17.   }            
  18. }

Raw Paste


Login or Register to edit or fork this paste. It's free.