• AVR Freaks

8, 16, 32 Bit access

Author
microLearner
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2017/02/27 20:26:37
  • Location: 0
  • Status: offline
2018/10/02 22:10:32 (permalink)
0

8, 16, 32 Bit access

When i read the term like the register supports 8-, 16-, 32 - bit access. What exactly does it mean? How can i do other bit access like 9 bit etc. Is it possible? I mean to say
I declare a variable like value and the name of the register is Reg1 is 32 bit then i can do this for 8 bit access
unsigned char value = Reg1; /* for 8 bit access */
unsigned short value = Reg1; /* for 16 bit access */
 
Am i correct?
 
#1

6 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17840
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/02 23:16:21 (permalink)
    4 (1)
    You are looking for general rules about very specific subjects. Your for instance is just that. It has no real answer.
    Computers tend to work in bytes of 8 bits each. Other size are possible. But most today are bytes. So things go 8,16,32,64.
    Many 32 bit CPUs gave instructions to handle data in 8 16 or 32 bit chunks.
    Some peripheral chips can be accessed in various size chunks too.

    And you are correct. It will on CPUs that support it.

    <edit>16, not 12
    post edited by NKurzman - 2018/10/03 05:39:32
    #2
    JPortici
    Super Member
    • Total Posts : 771
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/02 23:42:48 (permalink)
    5 (2)
    It means that the memory is organized in multiple of 8bits and that the cpu can get one frommemory byte at a time, two bytes at a time or four bytes at a time.
    Actually, in the case of the dsPIC because the data memory bus is 16 bit wide to move around 32bits it has to do it in two steps, 16 bit at a time... but the instruction set support a single instruction to do that
    so you have
    MOV.B that will move 8bits to/from, in a single cycle
    MOV that will move 16bits to/from, in a single cycle
    MOV.D that will move 32bits to/from, in two cycles (slightly different than doing two 16bit MOVs)
     
    does it mean it can't get 9bits? No, not natively. In fact, it can get 9 bits, but it's more complicated.
    The nine bits will be inside a 16bit block (hopefully aligned to an even address so they can be loaded/stored with a single MOV) they will be loaded, they will be rotated so the LSB is at bit0, they will be masked to gt rid of the unnecessary data, the operation will be performed on them, they will be masked again, they will be rotated back to their original position and they will be stored back.
     
    wooooah, that sounds incredibly tedious to do every time! yeah, but you have a C compiler that will do that for you.
    this is what already happens every time you modify a multi-bit parameter in the peripheral registers.
    LATAbits.LATA5 = 0

    well this can be translated in much more efficient contructs, the dsPIC can modify single bits in every register so all of this gets optimized to
    BCLR LATA,#5

     
    but this
    if (AD1CON1bits.CHS == 5)

    will execute as i said before
     
    so how do you do that?
    the C language helps you! read up on bitfields in C

    union {
      struct {
        unsigned singlebit:1;
        unsigned multibit:7;
      };
      unsigned char singlebyte;
    } bitfield;

     
    will create a bitfield variable where you can access the one bit field, the 7bit field, the whole byte variable
    #3
    microLearner
    Junior Member
    • Total Posts : 110
    • Reward points : 0
    • Joined: 2017/02/27 20:26:37
    • Location: 0
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/03 06:32:20 (permalink)
    0
    Thank you for the replies. Now i understand the statement means there are no assembly instructions for bit access. Am i correct?
    #4
    JPortici
    Super Member
    • Total Posts : 771
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/03 06:34:05 (permalink)
    4 (1)
    you can't LOAD single bits but in a PIC24/dsPIC you can
    -Test for single bits
    -SET/CLEAR/TOGGLE single bits
     
    document DS70000157G is the 16-Bit MCU and DSC Programmer’s Reference Manual
    Table 3-6 lists all the BIT oriented instructions
     
    interestingly enough in the new dsPIC33C family dedicated instructions have been added to extract/insert bitfields in two cycles
    post edited by JPortici - 2018/10/03 06:37:41
    #5
    du00000001
    Just Some Member
    • Total Posts : 3061
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/03 07:06:12 (permalink)
    4 (1)
    The 16-Bit (ds)PICs have instructions to set/toggle/clear single bits in bytes/words (address range limited to the lowest 8kBytes) and the W registers.
    The very same address limitation applies to bit testing.
     
    If interested in such issues, why don't you consult the "16-Bit MCU and DSC Programmer’s Reference Manual" ?
    (70000159g.pdf - to be found in the Documentation tab of every derivative it applies to.)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 17840
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: 8, 16, 32 Bit access 2018/10/03 10:18:56 (permalink)
    4 (2)
    microLearner
    Thank you for the replies. Now i understand the statement means there are no assembly instructions for bit access. Am i correct?

    You Need to reference your CPU.  Some have Bit instructions (ie PIC16) others do not (ie PIC32)
    And some of those with bit instructions have limits to what they can do. 
     
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5