This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

_lror_ doesn't work properly

Everytime I try to use the _lror_ it works fine several times... but if there's an overflow the variable is set to 0x00000000

//here's the test programm

void main(void)
{ unsigned long test = 0x80000000; test = _lror_(test,1);
}

//to get it working I created my own lror but it's a lot more bigger than the intrinsic _lror_

unsigned long lror(unsigned long input, unsigned int count)
{

unsigned int itmp1,itmp2; bit bit1,bit2;

while(count-->0) { itmp1 = input; input = input>>16; itmp2 = input; bit1 = itmp1 & 0x1; bit2 = itmp2 & 0x1; itmp1 &= 0xfffe; itmp2 &= 0xfffe; itmp1 |= bit2; itmp2 |= bit1; itmp1 = _iror_(itmp1,1); itmp2 = _iror_(itmp2,1); input = itmp2; input = input<<16; input |= itmp1; } return input;
}

Parents
  • You could also make your own routine by creating an assembly file called lol.a66 with something like...

    $SEGMENTED CASE MODV2
      NAME LROR
      NCODE   CGROUP  ?PR?LROR
      ASSUME  DPP3 : SYSTEM
      REGDEF  R0 - R15
    
      ?PR?LROR  SECTION  CODE WORD 'NCODE'
    
      LROR  PROC  NEAR
      GLOBAL  LROR
    
    LROR_loop:
      ROR   R8,#1
      ROR   R9,#1
      BMOV  R4.15,R9.15
      BMOV  R9.15,R8.15
      BMOV  R8.15,R4.15
      ADD   R10,#-1
      JMP   cc_NZ,LROR_loop
    
      MOV   R4,R8   ; return LSB
      MOV   R5,R9   ; return MSB
      RET
    
      LROR  ENDP
      ?PR?LROR  ENDS
    
      END
    

    In your C file call it (but make sure you don't have zero for the count).

    extern long LROR(long value, int count);
    
    void main(void) {
    
      volatile unsigned long test = 0x80000000ul;
    
      while(1) {
         test = LROR(test,1);
      };
    }
    

Reply
  • You could also make your own routine by creating an assembly file called lol.a66 with something like...

    $SEGMENTED CASE MODV2
      NAME LROR
      NCODE   CGROUP  ?PR?LROR
      ASSUME  DPP3 : SYSTEM
      REGDEF  R0 - R15
    
      ?PR?LROR  SECTION  CODE WORD 'NCODE'
    
      LROR  PROC  NEAR
      GLOBAL  LROR
    
    LROR_loop:
      ROR   R8,#1
      ROR   R9,#1
      BMOV  R4.15,R9.15
      BMOV  R9.15,R8.15
      BMOV  R8.15,R4.15
      ADD   R10,#-1
      JMP   cc_NZ,LROR_loop
    
      MOV   R4,R8   ; return LSB
      MOV   R5,R9   ; return MSB
      RET
    
      LROR  ENDP
      ?PR?LROR  ENDS
    
      END
    

    In your C file call it (but make sure you don't have zero for the count).

    extern long LROR(long value, int count);
    
    void main(void) {
    
      volatile unsigned long test = 0x80000000ul;
    
      while(1) {
         test = LROR(test,1);
      };
    }
    

Children