Another way to left shift a 32 bit data?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    Thanks Richard.

    Interesting approach!

    Ioannis

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    I don’t yet know if I’ve wrecked it in basic.

    Code:
    shifter byte
    offset byte
    array byte[7]
    
    
    shifter = 11
    offset = shifter >> 3            // byte in array to pass to whatever needs the 4 byte result, in this case 2
    array[3] = 1<<(shifter & 7)      // Set it to 00000000 (00000000 00000000 00001000 00000000) 00000000 00000000
    ‘dostuff with array[offset]

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    I could not follow that...

    Ioannis

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    So long as I have not ruined the way a C pointer will work...

    Before any input, the 32 bits you want could be anywhere within the 7 byte array.
    After computation, the memory location of the four bytes of the 32 bit value begins at array[offset].

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    Oh, I see. Thanks for the ideas.

    Still, asm rotate will be faster.

    Ioannis

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    I have my doubts, You only have to call it once.
    Assuming there is equal chance the input is 0-31, an assembler rotate routine will be called mean of 15 times.
    For a shift in either language the overhead is in finding the byte you want to shift.

    Again, assuming it’s still working. I’ll be able to try in PBP soon.

    If I’m mistaken and it’s not another trick you’ve worked out because of the known state of the array at the beginning, that would be helpful.
    It is currently taking me the equal number of assembler instructions as there are bytes in the array to bitwise rotate an array
    that has unknown contents at the beginning, which is the same as in the sixth post of this thread.
    Last edited by Art; - 12th December 2015 at 05:45.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: Another way to left shift a 32 bit data?

    I have a problem (what a surprise, huh?) with the MPLAB. It has a tool or something that helps to measure the exact time it takes for a routine to execute. No Osciloscopes, no pins to make high / low etc.

    Yes, the asm way will take from 1 to 32 times since we do not know the times to shift. But as you showed in #6, it takes give or take 5 asm instructions for one shift, max 32x5. Basic I think cannot beat that.

    Ioannis

Similar Threads

  1. how to "shift" a data into led matrix display ?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 9th January 2015, 16:09
  2. Bit Shift difference between PIC16 and PIC18 ???
    By bambi123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th February 2012, 01:04
  3. Shift Right, Left
    By tazntex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th July 2010, 15:28
  4. Replies: 2
    Last Post: - 7th March 2008, 02:16
  5. LCDOUT 4-bit data on 8-bit setting
    By breesy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th June 2006, 18:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts