简体   繁体   English

如何“不”在mips程序集中的寄存器

[英]How to “NOT” a register in mips assembly

既然mips汇编中没有NOT逻辑运算符,那么一个寄存器的内容怎么可能“不”呢?

You can use nor and the zero -register to fit everything into one instruction: 您可以使用norzero寄存器将所有内容放入一条指令中:

nor $<dest_reg>, $<in_reg>, $zero

The equivalent logical expressions would be: 等效的逻辑表达式为:

a nor 0 = not (a or 0) = not a

Another approach would be using xor and -1 as this is encoded as 1111...1111 in 2s-component. 另一种方法是使用xor-1因为它在2s分量中被编码为1111...1111

li $<help_reg>, -1                        # load -1 into help-register
xor $<dest_reg>, $<in_reg>, $<help_reg>   # actual not-operation

Equivalent logical expressions would be: 等效逻辑表达式为:

a xor 1 = (not a) and 1 = not a

Load -1 into another register, then XOR the registers. 将-1装入另一个寄存器,然后对寄存器进行XOR。

https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/bitwise.html https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/bitwise.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM