Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bit-reverse a byte on 68HC12

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 byte, so if the byte was 00000001, the output would be 10000000, or 00101011 to 11010100. We have to use assembly language, and were told we could use rotates and shifts (but not limited to!) to accomplish this task. I'm really at a loss as to where I should start.

like image 469
dohlfhauldhagen Avatar asked Feb 07 '11 17:02

dohlfhauldhagen


People also ask

How do you reverse a bit?

Repeating the same permutation twice returns to the original ordering on the items, so the bit reversal permutation is an involution. This permutation can be applied to any sequence in linear time while performing only simple index calculations.

What is reverse byte order?

Description. The Byte Reversal block changes the order of the bytes in data that you input to the block. Use this block when a process communicates between target computers that use different endianness, such as between Intel® processors that are little endian and other processors that are big endian.

How do you reverse a bit in Python?

Approach is very simple, Convert integer number into it's binary representation using bin(num) function. bin() function appends 0b as a prefix in binary representation of number, skip first two characters of binary representation and reverse remaining part of string.


2 Answers

When you do a right shift, what was the least significant bit goes into the carry flag.

When you do a rotate, the carry flag is used to fill in the vacated bit of the result (LSB for a ROL, MSB for a ROR).

like image 59
Jerry Coffin Avatar answered Sep 20 '22 14:09

Jerry Coffin


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

like image 29
Adi Bârsan Avatar answered Sep 19 '22 14:09

Adi Bârsan