1

I am working on a project where I need to take values contained in a hexadecimal value and split it. I will have a register that contains a value, 0xAA00BBCC and need to split it into 3 different integers, AA, BB, and CC

For example:

if the value is: 0x88000232, I need to split it into 3 integers: A: 88, B: 02, and C: 32.

How would I go about doing this?

austinm98
  • 15
  • 4
  • Hexadecimal is a serialization format for binary numbers. You probably mean your registers hold binary integers with those hex values, because the number you gave takes 8 hex digits, which (in ASCII) takes 8 bytes to represent. – Peter Cordes Oct 22 '18 at 23:37

1 Answers1

1

With a combination of SRL and ANDI, but sometimes one of them is unnecessary. For example:

srl $t0, $a0, 8
andi $t0, $t0, 0xFF

This shifts the value so that the BB from 0xAA00BBCC is at the bottom (0x00AA00BB) and then the andi resets the bits that don't belong to that BB part.

When the shift count is 24, the andi is not needed. And of course shifting by 0 positions is not useful so in that case only the andi is needed.

harold
  • 61,398
  • 6
  • 86
  • 164