Your inline assembler does this
asm(
"number: \n"
".long 0xFFFFFFFF \n"
[snip rest of array]
);
You then tell C that number is
extern unsigned char* number;
This says that number is a pointer to an unsigned character. Then you access it like this:
printf("%x ", number[0]);
This says to de-reference the pointer in number and return the first character. It would have been the same as doing:
printf("%x ", *(number+0));
Problem is that number was defined as a pointer. Assuming 32-bit pointers that translates to:
*(0xFFFFFFFF+0)
If you get a segfault it is probably because the address 0xFFFFFFFF is not accessible to your program.
You can change your extern statement to read:
extern unsigned char number[32];
Now number is an array of 32 unsigned characters. I'd be inclined to use the inttypes.h header and declare it as:
extern uint8_t number[32];
uint8_t is guaranteed to be 8 bits (or 1 byte). char on the other hand is defined as being a minimum of 8 bits (but can be more). However sizeof(char) will always return 1. I prefer uint8_t (unsigned 8 bit integers) just so you know you are dealing with 8 bit values which seems to be the case here. I'd modify the code to be:
#include <stdio.h>
#include <inttypes.h>
__asm__(
"number: \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFE \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFF \n"
".long 0xFFFFFFFF \n"
);
extern uint8_t number[32];
int main() {
printf("%x ", number[0]);
return 0;
}
Also note that if you intend to compile using GCC as C99 (will work with GCC's C89 as well) it is preferable to use __asm__ instead of asm since GCC's default is to disable the asm keyword (unless overridden with -fasm) when using -std=c99 option.
number is probably not a good name for an array of unsigned characters. It may cause confusion when someone has to come along and maintain your code.
char? (And "I have to use ... someone pointing a gun at you?)unsigned char *was right? That doesn't make any sense to me, at all. Perhapsextern int number[8];but I'm really out on a limb here.unsigned char *number, that means the value at the locationnumberrepresents holds an address or a pointer. In this case, that address or pointer is0xFFFFFFFF. Then when you dereference it asnumber[0], you are attempting to reference whatever is at address0xFFFFFFFF, which is invalid. Try"number: my_array\n"followed by"my_array:\n" prefacing your list of.long` values. Or try the method @unwind suggested.