How to isolate bits in Assembly

-1

I have a 32-bit word: 00000001001010100100000000100000

How can I isolate the first 6 most significant bits [31-26] and store it in a register? Is there any "recipe" to isolate a range of bits? How can I isolate a range of bits from a word?

Something like the link but I did not understand how I can apply it in my case.

If the question was not clear I can redo

    
asked by anonymous 13.10.2018 / 03:02

1 answer

0

If it is in the same register, you can only make a 26-bit right-side logical shift, so you would have the 6 bits in the byte of that register, like this:

;palavra longa no registrador [01111111 00000001 00100011 01000101]
lsr.l 0x1A, %REGISTRADOR% ; Logical Shit Right, ou seja deslocador lógico para a direita com 26 bis
;palavra longa no registrador após o deslocamento [00000000 00000000 0000000 00011111]

However, if you want to keep the bits in the same position, ignoring the others, just carry out logical operation E, with bits 1 where you want to keep, like this:

 ;palavra longa no registrador [01111111 00000001 00100011 01000101]
and.l 0xFC000000, %REGISTRADOR% ;0xFC000000 em binário é [11111100 00000000 00000000 00000000]
;palavra longa no registrador após operação E [01111100 00000000 0000000 0000000]

Following the truth table of the logical AND operation of the ALU, the bits that are in the high logic level will be kept, even those that are in logical low level in the original word, and the others will be ignored and will return in low logic level. (ALT + 3)

If the compiler in assembly allows the declaration in binary, it makes it easier, otherwise you can use the Windows calculator itself in the programmer function.     
17.10.2018 / 05:43