avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Using PSTR()


From: David Kelly
Subject: [avr-gcc-list] Using PSTR()
Date: Thu, 24 Mar 2005 23:21:05 -0600

When I originally wrote this I thought "avr-objdump -S" output showed proper handling of the string located in program (flash) memory. With avr-gcc 3.4.3 it no longer does. Then again it might never have. So the question is, "how to?"

What seems to be happening is that its reading the array from SRAM, but it doesn't appear to have been moved to SRAM on init. Don't really want it to be in SRAM but if it was then I might not have noticed.

#include <avr/pgmspace.h>
#include <inttype.h>

uint8_t
u_to_hex(uint8_t u)
{
        if( u < 16 )
                return( PSTR("01234567890ABCDEF")[u] );
        else
                return(0);
}

Command line used:
% avr-gcc -O -gdwarf-2 -Wall -ffreestanding -mmcu=atmega128 -c junk.c

"avr-objdump -S junk.o" says:

unsigned char
u_to_hex(uint8_t u)
{
        if( u < 16 )
  64:   80 31           cpi     r24, 0x10       ; 16
  66:   38 f4           brcc    .+14            ; 0x76
                return( PSTR("01234567890ABCDEF")[u] );
  68:   99 27           eor     r25, r25
  6a:   fc 01           movw    r30, r24
  6c:   e0 50           subi    r30, 0x00       ; 0
  6e:   f0 40           sbci    r31, 0x00       ; 0
  70:   80 81           ld      r24, Z
  72:   99 27           eor     r25, r25
  74:   08 95           ret
        else
                return(0);
  76:   80 e0           ldi     r24, 0x00       ; 0
  78:   90 e0           ldi     r25, 0x00       ; 0
}
  7a:   08 95           ret
  7c:   08 95           ret

How about that double "ret"? Know its been mentioned before. Isn't really hurting anything.

"avr-objdump -DS junk.o" spits out a lot but trimmed down this is the interesting extra. Seems to say that my string really is in progmem. Without PSTR() this would land in section .data rather than section .progmem.data:

Disassembly of section .progmem.data:

00000000 <__c.0>:
   0:   30 31           cpi     r19, 0x10       ; 16
   2:   32 33           cpi     r19, 0x32       ; 50
   4:   34 35           cpi     r19, 0x54       ; 84
   6:   36 37           cpi     r19, 0x76       ; 118
   8:   38 39           cpi     r19, 0x98       ; 152
   a:   30 41           sbci    r19, 0x10       ; 16
   c:   42 43           sbci    r20, 0x32       ; 50
   e:   44 45           sbci    r20, 0x54       ; 84
  10:   46 00           .word   0x0046  ; ????

--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]