Question

I'm trying to understand a program that I have disassembled. I'm understanding it so far.

However, I do not understand why the program is AND'ing an integer with 0x7F. It also likes to AND an integer with 0xFF. The program is somewhat of a random number generator.

What does this accomplish?

I think AND'ing with 0xFF takes the lower byte (of a register) and discards the rest?

Specifically in MIPS ASM:

## r2 = 0xfd    r3 = 0x10 ##

andi r2,r2,0x00ff       # What? Why?
andi r3,r3,0x007f       # What? Why?
Was it helpful?

Solution

"AND"ing with 0x7f is used to remove the most significant bit  as 0x7f is 0111 1111 and ensures that number is positive. "AND"ing with 0xff does the opposite.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top