Bit-reverse a byte on 68HC12

前端 未结 9 1597
挽巷
挽巷 2021-01-18 02:03

I\'m in a microprocessors class and we are using assembly language in Freescale CodeWarrior to program a 68HCS12 micro controller. Our assignment this week is to revers a by

相关标签:
9条回答
  • 2021-01-18 03:01

    This was a comment but I thought WTH!

    To save space over the 256 byte table you can have a 16 byte table containing the values for four bits (nibbles) at a time. The algorithm then would be

    revval=(revdigit[inval&0x0f]<<4)|
            revdigit[inval>>4];
    

    If I were a prof I'd certainly like the two parts where one shift is in the indexing and the other outside.

    0 讨论(0)
  • 2021-01-18 03:03

    If you can spare the 256 bytes extra code size, a lookup table is probably the most efficient way to reverse a byte on a 68HCS12. But I am pretty sure this is not what your instructor is expecting.

    For the "normal" solution, consider the data bits individually. Rotates and shifts allow you to move bits around. For a first solution, isolate the eight bits (with bitwise "and" operations), move them to their destination positions (shifts, rotates...), then combine them together again (with bitwise "or" operations). This will not be the most efficient or simplest implementation, but you should first concentrate on getting a correct result -- optimization can wait.

    0 讨论(0)
  • 2021-01-18 03:03

    For example, if you have in al the byte number the easiest way is

    mov al, 10101110
    mov ecx, 8
    

    we put 8 in ecx for loop

    mov ebx, 0 
    

    In bl we will havee the result, we will make ebx, only to see what happens better

    loop1:
    sal al, 1;           
    

    In carry flag now you have the last bit from left

    rcr bl, 1;           
    

    now you add in bl what you have in carry

    loop loop1
    

    and that's all

    0 讨论(0)
提交回复
热议问题