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.
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.
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.
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.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With