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?
有帮助吗?

解决方案

"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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top