asm rlc versus c shift<<

Discussion in 'Embedded Systems and Microcontrollers' started by embedtechnology, Apr 15, 2016.

  1. embedtechnology

    Thread Starter Member

    Dec 25, 2015
    I want to rotate a variable through another variable so that D7 bit of variable 0 will enter into bit D0 position of
    variable 1 ( like ASM: rlc variable 0, rlc variable 1 ) . But in c variable0<<=1 loads 0 into D0 position of variable0
    and removes bit D7. I am using mikroc compiler.Actually I want to develop a project which is nothing but a led massage
    display,in which row scanning technology is taken into consideration. The syntax is needed for scrolling function.
    Any idea please.
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    Left shift variable 1.
    Set or clear variable 1 lsb based on variable 0 msb.
    Left shift variable 0.

    Fancier ways to do it also exist.
  3. NorthGuy

    Active Member

    Jun 28, 2014
    In C, you would probably define a 16-bit variable then do

    Code (C):
    1. int x;
    2. x <<= 1;
    You can get the result of the shift from the high byte of the variable. In C it is:

    Code (C):
    1. char y;
    2. y = x >> 8;
    It may look like a long shift, but most compilers will know that it only means taking the high byte.