2

I have compiled this simple code on XC8 compiler and loaded the hex file into Picsimlab - simulator board (board 4) having PIC16f877a microcontroller.

    unsigned int x = 1;
    char *ptr = (char *) &x;

    if (*ptr == 1)
    {

        clcd_print("little Endian", LINE1(0));
    }
    else
    {
        clcd_print("big Endian", LINE1(0));
    } 

output: little endian

So can we deducde that Xc8 compiler follows little endian byte ordering system to program PIC16f877a?
Does that also mean that PIC16f877a stores variables into its data memory using little endian byte ordering system?

Can you please provide link to documentation mentioning about the byte ordering system followed by PIC16f877a and XC8 compiler?

0

1 Answer 1

6

Have a look at the user guide of the XC8 compiler. In chapter 5.4.2 you could read about the endianism of integer variables:

All integer values are represented in little endian format with the Least Significant Byte (LSB) at the lower address

Little endian is the default and only used endianism for all xc compilers.

The PIC16 family is a 8 Bit controller, so the controller itself don't had to care about endianess.

8
  • 4
    Although it's true that PIC16 doesn't care about endianness, some of the registers are logically wider than 8 bits and they are arranged in little endian format, like TMR1H:TMR1L.
    – Tagli
    Jul 9, 2020 at 10:15
  • 2
    @Mike Your statement is "The PIC16 family is a 8 Bit controller, so the controller itself don't had to care about endianness" How controller handles integers (2 bytes) if it does not care about endianness.
    – Babajan
    Jul 9, 2020 at 10:41
  • 1
    @Babajan It accesses them using two 8-bit instructions. The controller doesn't care about endianess, because it accesses 8-bits at a time. The compiler can then generate instructions that would interpret the lower address byte as having the most or least significant bits, the compiler can manipulate if the data are interpreted using which endianess.
    – KamilCuk
    Jul 9, 2020 at 11:29
  • 1
    The PIC itself is only thinking in one Byte, everything else is the job of the compiler. He put two bytes together to an int
    – Mike
    Jul 9, 2020 at 11:33
  • 1
    It's up to you. Just store MSB and LSB separate and it put together afterwards. So both (little and big endianess) will work. Just think byte by byte...
    – Mike
    Jul 9, 2020 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.