Here is a quick way for you to decode a one hot state value into a binary representation. This code is built for the MIPS32 architecture.
/*************************************
* One-Hot Decoder
* Usage: Convert the lower nibble of a 32bit
* one hot active low to a binary number
* representing the bit position.
* Input: $a0 for the hot value (IE: 0b1101)
* Output: $v0 is the decoded value (IE: 0x1)
*************************************/
.ent one_hot_decode
one_hot_decode:
//Invert the incoming ( Remove if Active High )
xori $a0, $a0, 0xF
//Count the number of leading zeros
clz $t1, $a0
//v0 = 31 - #zeros
li $t0, 31
subu $v0, $t0, $t1
jr $ra
nop
.end one_hot_decode |
/*************************************
* One-Hot Decoder
* Usage: Convert the lower nibble of a 32bit
* one hot active low to a binary number
* representing the bit position.
* Input: $a0 for the hot value (IE: 0b1101)
* Output: $v0 is the decoded value (IE: 0x1)
*************************************/
.ent one_hot_decode
one_hot_decode:
//Invert the incoming ( Remove if Active High )
xori $a0, $a0, 0xF
//Count the number of leading zeros
clz $t1, $a0
//v0 = 31 - #zeros
li $t0, 31
subu $v0, $t0, $t1
jr $ra
nop
.end one_hot_decode
This entry was posted
on Saturday, June 6th, 2009 at 3:12 pm and is filed under ASM, MIPS32.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.