andi with 0x7f deletes the most significant bit that is not used by ASCII (which uses only 7 bits or 0-128 to match characters). 0x7f is 0111 1111 in binary format. Since all AND with 0 (the most significant bit is 0, as you can see), 0, all AND with 1 remains unchanged, the operation deletes the most significant bit.
ori with 0x20 will only set the 6th bit (2 5 ). 0x20 - 0010 0000 in binary format. Since all ORs with 1 (the 6th bit, as you can see) are 1, and all ORs with 0 remain unchanged, this leads to the setting of the 6th bit.
As the commentary says, just in case r16 is initially less than 32 or in the case of r16> = 128 and <160, it will make the number> = 0x20. This does not mean that he will always add 0x20, though (for example, r16 was originally 32 --addi → 33 - andi → 33 --ori → 33).
As a side note, AND'ing with a constant (also called a mask) is usually used to extract a specific bit from the source data. And it will extract on any bit that the corresponding bit in the mask is 1.
OR'ing with a constant is usually used to set specific bit (s) to 1. It will set a bit whose corresponding bit in the mask is 1.
By the way, to set a specific bit to 0, you can AND with a constant that is 1, except for the bit you want to set. To switch certain bits, you can XOR with a constant with the corresponding bit 1, and the rest 0.
source share