Logical AND using only shift and rotate (32 bit)

I would like to replace the "AND" in the following set of instructions (in Assembly MIPS) with shift and rotate instructions only and obviously have the same result for any word

.text
main:
        la $a0,input            
        lw $t1,0($a0)           
        li $t0,0xFFF00FFF   #mask
        and $t2,$t1,$t0     
        li $v0,10
        syscall
        .data
input:  .word 0x12345678

I know for this particular mask that the answer is the following:

ror $t2, $t1, 9
srl $t2, $t2, 17
ror $t2, $t2, 6

I would like to know how are the above shifts/rotations calculated.

The output in binary is:

input : 00010010001101000101011001111000 ($t1)
mask  : 11111100000000000000000111111111 ($t0)

output: 00010000000000000000000001111000 ($t2)

Thanks in advance.



from Recent Questions - Stack Overflow https://ift.tt/2U4AcIA
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept