如何在MIPS中访问单词的各个位的状态? [英] How do I access the state of individual bits of a word in MIPS?
本文介绍了如何在MIPS中访问单词的各个位的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写程序,我需要确定是否设置了第3位和第6位.我知道我可以旋转一个单词或向左/向右移动它.
I'm writing a program and I need to determine if bits 3 and 6 are set. I know that I can rotate a word or left/right shift it.
但是如何访问单个位的状态?我是否使用像and/xor之类的按位运算符?
But how do I access individual bit's state? Do I use a bitwise operator like and/xor?
推荐答案
您将按位进行操作,并使用0x08和0x40(假定位0是最低位).您将使用andi指令执行此操作.
You would do a bitwise and with 0x08 and 0x40 (presuming bit 0 is the lowest order bit). You would use the andi instruction to do this.
如果$ t0是您要测试的值:
If $t0 is the value you want to test:
andi $t1, $t0, 0x08
andi $t2, $t0, 0x40
如果设置了第3位,$ t1将为非零,如果设置了第6位,则$ t2将为非零.
$t1 will be non-zero if bit 3 is set, $t2 will be non-zero if bit 6 is set.
这篇关于如何在MIPS中访问单词的各个位的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文