Length difference between bytes and pc unit












0















I am currently working with Microchip system and I have encountered program length problem. I can see two different length while compiling:




  • length (PC unit)

  • length (bytes)


And those two can really differ (0x1EC8 and 0x2700 for instance).



Do any of you know the difference between the two? Method to calculate them?



[EDIT] :
See .text section



enter image description here










share|improve this question




















  • 1





    What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

    – Clifford
    Nov 26 '18 at 18:02
















0















I am currently working with Microchip system and I have encountered program length problem. I can see two different length while compiling:




  • length (PC unit)

  • length (bytes)


And those two can really differ (0x1EC8 and 0x2700 for instance).



Do any of you know the difference between the two? Method to calculate them?



[EDIT] :
See .text section



enter image description here










share|improve this question




















  • 1





    What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

    – Clifford
    Nov 26 '18 at 18:02














0












0








0








I am currently working with Microchip system and I have encountered program length problem. I can see two different length while compiling:




  • length (PC unit)

  • length (bytes)


And those two can really differ (0x1EC8 and 0x2700 for instance).



Do any of you know the difference between the two? Method to calculate them?



[EDIT] :
See .text section



enter image description here










share|improve this question
















I am currently working with Microchip system and I have encountered program length problem. I can see two different length while compiling:




  • length (PC unit)

  • length (bytes)


And those two can really differ (0x1EC8 and 0x2700 for instance).



Do any of you know the difference between the two? Method to calculate them?



[EDIT] :
See .text section



enter image description here







embedded pic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 11:54









Lundin

112k17163271




112k17163271










asked Nov 26 '18 at 9:07









Le LaboureurLe Laboureur

396




396








  • 1





    What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

    – Clifford
    Nov 26 '18 at 18:02














  • 1





    What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

    – Clifford
    Nov 26 '18 at 18:02








1




1





What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

– Clifford
Nov 26 '18 at 18:02





What particular PIC device do you have? Different device families have varying instruction width and instruction memory addressability (en.wikipedia.org/wiki/PIC_microcontrollers#Word_size). The Program Counter increments in instruction width units - that accounts for the difference.

– Clifford
Nov 26 '18 at 18:02












4 Answers
4






active

oldest

votes


















0














I just gone through some books and got these explanations, it might be useful for you.




Bytes:



There is a minimum block of code that is always generated by the MPLAB
C compiler



Taken from the book: here




and




PC Units:



It may be Program Counter units. It is indicated that, The 16-bit
device PC increments by 2 for each instruction word (Not in all cases, please refer some books for PC increment in PICs)



Taken from the book: here



Page No: 52




So, they may not be the same size. Mostly Bytes size will be larger than PC Units.



Hope it is helpful :)






share|improve this answer


























  • The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

    – too honest for this site
    Dec 2 '18 at 9:08





















2














Maybe have a look at the PIC24FJ128GA:

Each instruction is 24 Bit or three Byte. The user Flash Program Memory starts at 0x200 and has a length of 0x155FC in Program Counter Units. Each even PC has two bytes and each odd PC has just one byte. So the total user program memory is 0x155FC * 1.5 = 131322 = 128.2K-byte.



enter image description here






share|improve this answer


























  • No the instruction length is 12 bit!

    – GJ.
    Nov 26 '18 at 19:56











  • The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

    – Mike
    Nov 27 '18 at 6:44











  • Yes, I use a PIC24FJ256GB110

    – Le Laboureur
    Nov 27 '18 at 8:09











  • @Le Laboureur OK then my explanation is correct.

    – Mike
    Nov 27 '18 at 8:17



















0














This answer is focused on just the Microchip PIC devices in the PIC24, dsPIC30, and dsPIC33 families.



Controllers of this type have separated address buses for instruction and data memory.



The data memory is organized as 16-bit words and addressable as bytes.



The instruction memory is organized as 24-bit words.



When an op-code is fetched from the instruction memory all 24-bits are read at once.
But there are additional addressing modes that allow a portion of the instruction memory to be read using addressing modes available with data memory.



There are some other ways to access instruction memory but they are about erasing and writing the instruction memory so are not relevant to this answer.



When the controller is fetching instructions using only the program counter only even address are possible however it is possible to fetch instruction using indirect addressing. Developers should be careful using this method for control transfer like CALL and GOTO as address error traps can occur when the target address is odd.



For reasons I do not fully comprehend the portions of instruction memory visible using the modes available with data memory can only access the low 16-bits of an instruction word, the upper 8-bit cannot be accessed this way.



So I have described the shape of the memory buses in the 24-bit PICs but I've not answered your question.



Microchip documentation does not do a good job of describing this. It does a lot of hand waving and obscures useful details.



In essence there are 2 address units for every word of addressable memory. In the data memory this represents 2 bytes of RAM, for instruction memory the represents 3 bytes of FLASH, but one 2 of those 3 bytes are visible.



This treatment of instruction memory is "supposed" to make accessing this memory space for to read constant data faster and easier to create a C compiler code generator for. Hard to say it that is true.



So to sum up there are 3 bytes of FLASH for each instruction word. Each instruction word is represented by 2 address units.



To convert from address units to bytes of FLASH:




  1. Count the range of FLASH address units (must be even).

  2. Divide range by 2 to get the number of instruction words.

  3. Multiply the number of instruction words by 3 for the number of bytes of FLASH memory.


For most practical purposes the number of bytes used of FLASH memory is of little use, though the number of instruction word assigned or free is more useful.






share|improve this answer































    -2














    PC means program counter, so in that case the size is being given in program counter units (which depends on the length of the instructions and it determines the number of possible address that the PC can point to). In the other case, it just means the size in bytes.



    In a constant-width instruction as a Microchip PIC24 is (which could match with your example), the instruction width is 3bytes, being the PC (never odd) incremented by 2 each instruction (16-bit data). So the relation between the length in bytes and the length in PC units is 3/2, in your example, a .text section of 0x1b0 bytes will be equivalent to 0x1b0 * (2 / 3) = 288 PC-Units



    The term PC unit is an useful way to speak about addresses in devices whose instruction's width is bigger than 8-bites, especially for debugging (map files, addresses, offsets, sizes, etc), but I highly recommend you to work always in PC-units or always in bytes, in order to avoid stupid errors.



    Bear in mind that several Microchip operators work with PC units, instead of bytes, such as .sizeof.., so these kind of operators won't report you the size in bytes, so you will have to know the architecture of your uC in case you want to convert to bytes.






    share|improve this answer


























    • Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

      – Le Laboureur
      Nov 26 '18 at 9:37











    • and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

      – Le Laboureur
      Nov 26 '18 at 9:50






    • 1





      This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

      – Clifford
      Nov 26 '18 at 17:58











    • @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

      – Clifford
      Nov 26 '18 at 18:03






    • 2





      You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

      – Clifford
      Nov 26 '18 at 19:50












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477738%2flength-difference-between-bytes-and-pc-unit%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I just gone through some books and got these explanations, it might be useful for you.




    Bytes:



    There is a minimum block of code that is always generated by the MPLAB
    C compiler



    Taken from the book: here




    and




    PC Units:



    It may be Program Counter units. It is indicated that, The 16-bit
    device PC increments by 2 for each instruction word (Not in all cases, please refer some books for PC increment in PICs)



    Taken from the book: here



    Page No: 52




    So, they may not be the same size. Mostly Bytes size will be larger than PC Units.



    Hope it is helpful :)






    share|improve this answer


























    • The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

      – too honest for this site
      Dec 2 '18 at 9:08


















    0














    I just gone through some books and got these explanations, it might be useful for you.




    Bytes:



    There is a minimum block of code that is always generated by the MPLAB
    C compiler



    Taken from the book: here




    and




    PC Units:



    It may be Program Counter units. It is indicated that, The 16-bit
    device PC increments by 2 for each instruction word (Not in all cases, please refer some books for PC increment in PICs)



    Taken from the book: here



    Page No: 52




    So, they may not be the same size. Mostly Bytes size will be larger than PC Units.



    Hope it is helpful :)






    share|improve this answer


























    • The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

      – too honest for this site
      Dec 2 '18 at 9:08
















    0












    0








    0







    I just gone through some books and got these explanations, it might be useful for you.




    Bytes:



    There is a minimum block of code that is always generated by the MPLAB
    C compiler



    Taken from the book: here




    and




    PC Units:



    It may be Program Counter units. It is indicated that, The 16-bit
    device PC increments by 2 for each instruction word (Not in all cases, please refer some books for PC increment in PICs)



    Taken from the book: here



    Page No: 52




    So, they may not be the same size. Mostly Bytes size will be larger than PC Units.



    Hope it is helpful :)






    share|improve this answer















    I just gone through some books and got these explanations, it might be useful for you.




    Bytes:



    There is a minimum block of code that is always generated by the MPLAB
    C compiler



    Taken from the book: here




    and




    PC Units:



    It may be Program Counter units. It is indicated that, The 16-bit
    device PC increments by 2 for each instruction word (Not in all cases, please refer some books for PC increment in PICs)



    Taken from the book: here



    Page No: 52




    So, they may not be the same size. Mostly Bytes size will be larger than PC Units.



    Hope it is helpful :)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 2 '18 at 11:53

























    answered Nov 26 '18 at 10:19









    Surenthar PitchaiSurenthar Pitchai

    519413




    519413













    • The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

      – too honest for this site
      Dec 2 '18 at 9:08





















    • The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

      – too honest for this site
      Dec 2 '18 at 9:08



















    The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

    – too honest for this site
    Dec 2 '18 at 9:08







    The PIC (except the PIC32 which has a MIPS core) PC increments by 1, not 2 except for skip instructions (which increment by either 1 or 2, depending on condition).

    – too honest for this site
    Dec 2 '18 at 9:08















    2














    Maybe have a look at the PIC24FJ128GA:

    Each instruction is 24 Bit or three Byte. The user Flash Program Memory starts at 0x200 and has a length of 0x155FC in Program Counter Units. Each even PC has two bytes and each odd PC has just one byte. So the total user program memory is 0x155FC * 1.5 = 131322 = 128.2K-byte.



    enter image description here






    share|improve this answer


























    • No the instruction length is 12 bit!

      – GJ.
      Nov 26 '18 at 19:56











    • The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

      – Mike
      Nov 27 '18 at 6:44











    • Yes, I use a PIC24FJ256GB110

      – Le Laboureur
      Nov 27 '18 at 8:09











    • @Le Laboureur OK then my explanation is correct.

      – Mike
      Nov 27 '18 at 8:17
















    2














    Maybe have a look at the PIC24FJ128GA:

    Each instruction is 24 Bit or three Byte. The user Flash Program Memory starts at 0x200 and has a length of 0x155FC in Program Counter Units. Each even PC has two bytes and each odd PC has just one byte. So the total user program memory is 0x155FC * 1.5 = 131322 = 128.2K-byte.



    enter image description here






    share|improve this answer


























    • No the instruction length is 12 bit!

      – GJ.
      Nov 26 '18 at 19:56











    • The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

      – Mike
      Nov 27 '18 at 6:44











    • Yes, I use a PIC24FJ256GB110

      – Le Laboureur
      Nov 27 '18 at 8:09











    • @Le Laboureur OK then my explanation is correct.

      – Mike
      Nov 27 '18 at 8:17














    2












    2








    2







    Maybe have a look at the PIC24FJ128GA:

    Each instruction is 24 Bit or three Byte. The user Flash Program Memory starts at 0x200 and has a length of 0x155FC in Program Counter Units. Each even PC has two bytes and each odd PC has just one byte. So the total user program memory is 0x155FC * 1.5 = 131322 = 128.2K-byte.



    enter image description here






    share|improve this answer















    Maybe have a look at the PIC24FJ128GA:

    Each instruction is 24 Bit or three Byte. The user Flash Program Memory starts at 0x200 and has a length of 0x155FC in Program Counter Units. Each even PC has two bytes and each odd PC has just one byte. So the total user program memory is 0x155FC * 1.5 = 131322 = 128.2K-byte.



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 26 '18 at 12:20

























    answered Nov 26 '18 at 12:12









    MikeMike

    2,1102825




    2,1102825













    • No the instruction length is 12 bit!

      – GJ.
      Nov 26 '18 at 19:56











    • The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

      – Mike
      Nov 27 '18 at 6:44











    • Yes, I use a PIC24FJ256GB110

      – Le Laboureur
      Nov 27 '18 at 8:09











    • @Le Laboureur OK then my explanation is correct.

      – Mike
      Nov 27 '18 at 8:17



















    • No the instruction length is 12 bit!

      – GJ.
      Nov 26 '18 at 19:56











    • The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

      – Mike
      Nov 27 '18 at 6:44











    • Yes, I use a PIC24FJ256GB110

      – Le Laboureur
      Nov 27 '18 at 8:09











    • @Le Laboureur OK then my explanation is correct.

      – Mike
      Nov 27 '18 at 8:17

















    No the instruction length is 12 bit!

    – GJ.
    Nov 26 '18 at 19:56





    No the instruction length is 12 bit!

    – GJ.
    Nov 26 '18 at 19:56













    The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

    – Mike
    Nov 27 '18 at 6:44





    The instruction length depends on the PIC. A PIC24 has got a 24 Bit Instruction length.

    – Mike
    Nov 27 '18 at 6:44













    Yes, I use a PIC24FJ256GB110

    – Le Laboureur
    Nov 27 '18 at 8:09





    Yes, I use a PIC24FJ256GB110

    – Le Laboureur
    Nov 27 '18 at 8:09













    @Le Laboureur OK then my explanation is correct.

    – Mike
    Nov 27 '18 at 8:17





    @Le Laboureur OK then my explanation is correct.

    – Mike
    Nov 27 '18 at 8:17











    0














    This answer is focused on just the Microchip PIC devices in the PIC24, dsPIC30, and dsPIC33 families.



    Controllers of this type have separated address buses for instruction and data memory.



    The data memory is organized as 16-bit words and addressable as bytes.



    The instruction memory is organized as 24-bit words.



    When an op-code is fetched from the instruction memory all 24-bits are read at once.
    But there are additional addressing modes that allow a portion of the instruction memory to be read using addressing modes available with data memory.



    There are some other ways to access instruction memory but they are about erasing and writing the instruction memory so are not relevant to this answer.



    When the controller is fetching instructions using only the program counter only even address are possible however it is possible to fetch instruction using indirect addressing. Developers should be careful using this method for control transfer like CALL and GOTO as address error traps can occur when the target address is odd.



    For reasons I do not fully comprehend the portions of instruction memory visible using the modes available with data memory can only access the low 16-bits of an instruction word, the upper 8-bit cannot be accessed this way.



    So I have described the shape of the memory buses in the 24-bit PICs but I've not answered your question.



    Microchip documentation does not do a good job of describing this. It does a lot of hand waving and obscures useful details.



    In essence there are 2 address units for every word of addressable memory. In the data memory this represents 2 bytes of RAM, for instruction memory the represents 3 bytes of FLASH, but one 2 of those 3 bytes are visible.



    This treatment of instruction memory is "supposed" to make accessing this memory space for to read constant data faster and easier to create a C compiler code generator for. Hard to say it that is true.



    So to sum up there are 3 bytes of FLASH for each instruction word. Each instruction word is represented by 2 address units.



    To convert from address units to bytes of FLASH:




    1. Count the range of FLASH address units (must be even).

    2. Divide range by 2 to get the number of instruction words.

    3. Multiply the number of instruction words by 3 for the number of bytes of FLASH memory.


    For most practical purposes the number of bytes used of FLASH memory is of little use, though the number of instruction word assigned or free is more useful.






    share|improve this answer




























      0














      This answer is focused on just the Microchip PIC devices in the PIC24, dsPIC30, and dsPIC33 families.



      Controllers of this type have separated address buses for instruction and data memory.



      The data memory is organized as 16-bit words and addressable as bytes.



      The instruction memory is organized as 24-bit words.



      When an op-code is fetched from the instruction memory all 24-bits are read at once.
      But there are additional addressing modes that allow a portion of the instruction memory to be read using addressing modes available with data memory.



      There are some other ways to access instruction memory but they are about erasing and writing the instruction memory so are not relevant to this answer.



      When the controller is fetching instructions using only the program counter only even address are possible however it is possible to fetch instruction using indirect addressing. Developers should be careful using this method for control transfer like CALL and GOTO as address error traps can occur when the target address is odd.



      For reasons I do not fully comprehend the portions of instruction memory visible using the modes available with data memory can only access the low 16-bits of an instruction word, the upper 8-bit cannot be accessed this way.



      So I have described the shape of the memory buses in the 24-bit PICs but I've not answered your question.



      Microchip documentation does not do a good job of describing this. It does a lot of hand waving and obscures useful details.



      In essence there are 2 address units for every word of addressable memory. In the data memory this represents 2 bytes of RAM, for instruction memory the represents 3 bytes of FLASH, but one 2 of those 3 bytes are visible.



      This treatment of instruction memory is "supposed" to make accessing this memory space for to read constant data faster and easier to create a C compiler code generator for. Hard to say it that is true.



      So to sum up there are 3 bytes of FLASH for each instruction word. Each instruction word is represented by 2 address units.



      To convert from address units to bytes of FLASH:




      1. Count the range of FLASH address units (must be even).

      2. Divide range by 2 to get the number of instruction words.

      3. Multiply the number of instruction words by 3 for the number of bytes of FLASH memory.


      For most practical purposes the number of bytes used of FLASH memory is of little use, though the number of instruction word assigned or free is more useful.






      share|improve this answer


























        0












        0








        0







        This answer is focused on just the Microchip PIC devices in the PIC24, dsPIC30, and dsPIC33 families.



        Controllers of this type have separated address buses for instruction and data memory.



        The data memory is organized as 16-bit words and addressable as bytes.



        The instruction memory is organized as 24-bit words.



        When an op-code is fetched from the instruction memory all 24-bits are read at once.
        But there are additional addressing modes that allow a portion of the instruction memory to be read using addressing modes available with data memory.



        There are some other ways to access instruction memory but they are about erasing and writing the instruction memory so are not relevant to this answer.



        When the controller is fetching instructions using only the program counter only even address are possible however it is possible to fetch instruction using indirect addressing. Developers should be careful using this method for control transfer like CALL and GOTO as address error traps can occur when the target address is odd.



        For reasons I do not fully comprehend the portions of instruction memory visible using the modes available with data memory can only access the low 16-bits of an instruction word, the upper 8-bit cannot be accessed this way.



        So I have described the shape of the memory buses in the 24-bit PICs but I've not answered your question.



        Microchip documentation does not do a good job of describing this. It does a lot of hand waving and obscures useful details.



        In essence there are 2 address units for every word of addressable memory. In the data memory this represents 2 bytes of RAM, for instruction memory the represents 3 bytes of FLASH, but one 2 of those 3 bytes are visible.



        This treatment of instruction memory is "supposed" to make accessing this memory space for to read constant data faster and easier to create a C compiler code generator for. Hard to say it that is true.



        So to sum up there are 3 bytes of FLASH for each instruction word. Each instruction word is represented by 2 address units.



        To convert from address units to bytes of FLASH:




        1. Count the range of FLASH address units (must be even).

        2. Divide range by 2 to get the number of instruction words.

        3. Multiply the number of instruction words by 3 for the number of bytes of FLASH memory.


        For most practical purposes the number of bytes used of FLASH memory is of little use, though the number of instruction word assigned or free is more useful.






        share|improve this answer













        This answer is focused on just the Microchip PIC devices in the PIC24, dsPIC30, and dsPIC33 families.



        Controllers of this type have separated address buses for instruction and data memory.



        The data memory is organized as 16-bit words and addressable as bytes.



        The instruction memory is organized as 24-bit words.



        When an op-code is fetched from the instruction memory all 24-bits are read at once.
        But there are additional addressing modes that allow a portion of the instruction memory to be read using addressing modes available with data memory.



        There are some other ways to access instruction memory but they are about erasing and writing the instruction memory so are not relevant to this answer.



        When the controller is fetching instructions using only the program counter only even address are possible however it is possible to fetch instruction using indirect addressing. Developers should be careful using this method for control transfer like CALL and GOTO as address error traps can occur when the target address is odd.



        For reasons I do not fully comprehend the portions of instruction memory visible using the modes available with data memory can only access the low 16-bits of an instruction word, the upper 8-bit cannot be accessed this way.



        So I have described the shape of the memory buses in the 24-bit PICs but I've not answered your question.



        Microchip documentation does not do a good job of describing this. It does a lot of hand waving and obscures useful details.



        In essence there are 2 address units for every word of addressable memory. In the data memory this represents 2 bytes of RAM, for instruction memory the represents 3 bytes of FLASH, but one 2 of those 3 bytes are visible.



        This treatment of instruction memory is "supposed" to make accessing this memory space for to read constant data faster and easier to create a C compiler code generator for. Hard to say it that is true.



        So to sum up there are 3 bytes of FLASH for each instruction word. Each instruction word is represented by 2 address units.



        To convert from address units to bytes of FLASH:




        1. Count the range of FLASH address units (must be even).

        2. Divide range by 2 to get the number of instruction words.

        3. Multiply the number of instruction words by 3 for the number of bytes of FLASH memory.


        For most practical purposes the number of bytes used of FLASH memory is of little use, though the number of instruction word assigned or free is more useful.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 5 '18 at 2:12









        Dan1138Dan1138

        2717




        2717























            -2














            PC means program counter, so in that case the size is being given in program counter units (which depends on the length of the instructions and it determines the number of possible address that the PC can point to). In the other case, it just means the size in bytes.



            In a constant-width instruction as a Microchip PIC24 is (which could match with your example), the instruction width is 3bytes, being the PC (never odd) incremented by 2 each instruction (16-bit data). So the relation between the length in bytes and the length in PC units is 3/2, in your example, a .text section of 0x1b0 bytes will be equivalent to 0x1b0 * (2 / 3) = 288 PC-Units



            The term PC unit is an useful way to speak about addresses in devices whose instruction's width is bigger than 8-bites, especially for debugging (map files, addresses, offsets, sizes, etc), but I highly recommend you to work always in PC-units or always in bytes, in order to avoid stupid errors.



            Bear in mind that several Microchip operators work with PC units, instead of bytes, such as .sizeof.., so these kind of operators won't report you the size in bytes, so you will have to know the architecture of your uC in case you want to convert to bytes.






            share|improve this answer


























            • Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

              – Le Laboureur
              Nov 26 '18 at 9:37











            • and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

              – Le Laboureur
              Nov 26 '18 at 9:50






            • 1





              This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

              – Clifford
              Nov 26 '18 at 17:58











            • @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

              – Clifford
              Nov 26 '18 at 18:03






            • 2





              You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

              – Clifford
              Nov 26 '18 at 19:50
















            -2














            PC means program counter, so in that case the size is being given in program counter units (which depends on the length of the instructions and it determines the number of possible address that the PC can point to). In the other case, it just means the size in bytes.



            In a constant-width instruction as a Microchip PIC24 is (which could match with your example), the instruction width is 3bytes, being the PC (never odd) incremented by 2 each instruction (16-bit data). So the relation between the length in bytes and the length in PC units is 3/2, in your example, a .text section of 0x1b0 bytes will be equivalent to 0x1b0 * (2 / 3) = 288 PC-Units



            The term PC unit is an useful way to speak about addresses in devices whose instruction's width is bigger than 8-bites, especially for debugging (map files, addresses, offsets, sizes, etc), but I highly recommend you to work always in PC-units or always in bytes, in order to avoid stupid errors.



            Bear in mind that several Microchip operators work with PC units, instead of bytes, such as .sizeof.., so these kind of operators won't report you the size in bytes, so you will have to know the architecture of your uC in case you want to convert to bytes.






            share|improve this answer


























            • Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

              – Le Laboureur
              Nov 26 '18 at 9:37











            • and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

              – Le Laboureur
              Nov 26 '18 at 9:50






            • 1





              This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

              – Clifford
              Nov 26 '18 at 17:58











            • @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

              – Clifford
              Nov 26 '18 at 18:03






            • 2





              You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

              – Clifford
              Nov 26 '18 at 19:50














            -2












            -2








            -2







            PC means program counter, so in that case the size is being given in program counter units (which depends on the length of the instructions and it determines the number of possible address that the PC can point to). In the other case, it just means the size in bytes.



            In a constant-width instruction as a Microchip PIC24 is (which could match with your example), the instruction width is 3bytes, being the PC (never odd) incremented by 2 each instruction (16-bit data). So the relation between the length in bytes and the length in PC units is 3/2, in your example, a .text section of 0x1b0 bytes will be equivalent to 0x1b0 * (2 / 3) = 288 PC-Units



            The term PC unit is an useful way to speak about addresses in devices whose instruction's width is bigger than 8-bites, especially for debugging (map files, addresses, offsets, sizes, etc), but I highly recommend you to work always in PC-units or always in bytes, in order to avoid stupid errors.



            Bear in mind that several Microchip operators work with PC units, instead of bytes, such as .sizeof.., so these kind of operators won't report you the size in bytes, so you will have to know the architecture of your uC in case you want to convert to bytes.






            share|improve this answer















            PC means program counter, so in that case the size is being given in program counter units (which depends on the length of the instructions and it determines the number of possible address that the PC can point to). In the other case, it just means the size in bytes.



            In a constant-width instruction as a Microchip PIC24 is (which could match with your example), the instruction width is 3bytes, being the PC (never odd) incremented by 2 each instruction (16-bit data). So the relation between the length in bytes and the length in PC units is 3/2, in your example, a .text section of 0x1b0 bytes will be equivalent to 0x1b0 * (2 / 3) = 288 PC-Units



            The term PC unit is an useful way to speak about addresses in devices whose instruction's width is bigger than 8-bites, especially for debugging (map files, addresses, offsets, sizes, etc), but I highly recommend you to work always in PC-units or always in bytes, in order to avoid stupid errors.



            Bear in mind that several Microchip operators work with PC units, instead of bytes, such as .sizeof.., so these kind of operators won't report you the size in bytes, so you will have to know the architecture of your uC in case you want to convert to bytes.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 27 '18 at 14:19

























            answered Nov 26 '18 at 9:29









            JoseJose

            1,291516




            1,291516













            • Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

              – Le Laboureur
              Nov 26 '18 at 9:37











            • and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

              – Le Laboureur
              Nov 26 '18 at 9:50






            • 1





              This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

              – Clifford
              Nov 26 '18 at 17:58











            • @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

              – Clifford
              Nov 26 '18 at 18:03






            • 2





              You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

              – Clifford
              Nov 26 '18 at 19:50



















            • Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

              – Le Laboureur
              Nov 26 '18 at 9:37











            • and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

              – Le Laboureur
              Nov 26 '18 at 9:50






            • 1





              This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

              – Clifford
              Nov 26 '18 at 17:58











            • @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

              – Clifford
              Nov 26 '18 at 18:03






            • 2





              You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

              – Clifford
              Nov 26 '18 at 19:50

















            Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

            – Le Laboureur
            Nov 26 '18 at 9:37





            Thanks for the explanation, however the length are in order and length(PC unit) < length(bytes)

            – Le Laboureur
            Nov 26 '18 at 9:37













            and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

            – Le Laboureur
            Nov 26 '18 at 9:50





            and the difference between the two is way too high I just added a screenshot, maybe it will help understand the pb

            – Le Laboureur
            Nov 26 '18 at 9:50




            1




            1





            This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

            – Clifford
            Nov 26 '18 at 17:58





            This answer is nonsense - the output is form the linker for a PIC compiler and nothing to do with disk storage. PC in this context refers to program counter and PIC devices have instruction words that are not a multiple of 8 bits.

            – Clifford
            Nov 26 '18 at 17:58













            @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

            – Clifford
            Nov 26 '18 at 18:03





            @LeLaboureur : If you disagree with the answer (and you are right to do so), why did you accept it?

            – Clifford
            Nov 26 '18 at 18:03




            2




            2





            You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

            – Clifford
            Nov 26 '18 at 19:50





            You should perhaps delete the original answer and just leave the edit - leaving incorrect information in an answer serves no purpose. That said the edit is not accurate either. It depends on the specific PIC family, but, for those with 12 and 14 bit instruction words, the instruction memory is only addressable in those units, so the byte size has no relationship to absolute addresses.

            – Clifford
            Nov 26 '18 at 19:50


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477738%2flength-difference-between-bytes-and-pc-unit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen