Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22134

How to declare 16-bits pointer to string in GCC C compiler for arm processor

$
0
0

I tried to declare 16-bits pointers to strings in GNU GCC C compiler for ARM to reduce flash consumption. I have about 200 strings in two language, so reducing the size of pointer i could save 800 bytes of flash.

At first i tried to do declare 32-bits pointer as "unsigned int" in C and that was OK:

const unsigned char str1[] ="Hello word";const unsigned int ptr1 = &str1;

then i tried to reduce pointer to 16 bits:

const  unsigned short ptr1 = &str1;

and i got error:"error: initializer element is not computable at load time"

Then i tried:

const unsigned short ptr1 = (&str1 & 0xFFFF);

and i got:"error: invalid operands to binary & (have 'const unsigned char (*)[11]' and 'int')"

After many attempts i ended up in assembly:

  .section .rodata.strings  .align 2ptr0:ptr3:   .short (str3-str0)ptr4:   .short (str4-str0)str0:str3:   .asciz  "3-th string"str4:   .asciz  "4-th string"

compilation pass well, but now i have problem trying to reference pointers: ptr4 and ptr0 from C code. Trying to pass "ptr4-ptr0" as an 8-bit argument to C function:

getStringFromTable (ptr4-ptr0)

declared as:

void getStringFromTable (unsigned char stringIndex)

i got wrong code like this:

ldr     r3, [pc, #28]   ; (0x8000a78 <main+164>)ldrb    r1, [r3, #0]ldr     r3, [pc, #28]   ; (0x8000a7c <main+168>)ldrb    r3, [r3, #0]subs    r1, r1, r3uxtb    r1, r1bl      0x8000692 <getStringFromTable>

instead of something like this:

movs    r0, #2bl      0x8000692 <getStringFromTable>

I would be grateful for any suggestion.


Viewing all articles
Browse latest Browse all 22134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>