汇编 6800 循环?测试字中的特定位

发布于 2024-09-01 00:56:23 字数 449 浏览 4 评论 0原文

试图帮助朋友与朋友一起解决一些汇编代码,但我遇到了一个小问题。

我正在尝试弄清楚如何循环 8 位二进制字并检查特定位的值。我需要检查第 1、3、5 和 1 位。 7 看看它们是否为 1。

int count = 1; 
int bitAdd = 0;
foreach (var bit in word) {
    if ((count = 1 && bit = 1) || (count = 3 && bit = 1) || (count = 5 && bit = 1) || (count = 7 && bit = 1)) {
      bitAdd += 1;
    }
    count += 1;
}

非常感谢帮助。

//编辑 抱歉,pusdo 代码有点含糊。试图让它更简洁一些。

Trying to help a friend out with a friend out with some assembly code, but I've run into a small problem.

I'm trying to work out how I would loop through a 8 bit binary word and check the value of specific bits. I need to check bits 1, 3, 5 & 7 to see if they are 1.

i.e.

int count = 1; 
int bitAdd = 0;
foreach (var bit in word) {
    if ((count = 1 && bit = 1) || (count = 3 && bit = 1) || (count = 5 && bit = 1) || (count = 7 && bit = 1)) {
      bitAdd += 1;
    }
    count += 1;
}

Help is much appreciated.

//Edit
Sorry, pusdo code was a bit ambiguous. Tried to make it a little more succinct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荆棘i 2024-09-08 00:56:23

我认为 BTST 指令在这里对您有用。

http://68k.hax.com/BTST

例如:

btst #5, d0

将检查值中是否为第 5 位在 d0 中设置。

(这适用于 68000,我不太确定 6800,谷歌搜索告诉我 BITA 或 BITB 指令可能有用:http://www.textfiles.com/programming/CARDS/6800 )

I think the BTST instruction will be of use to you here.

http://68k.hax.com/BTST

For example:

btst #5, d0

Will check if bit 5 in the value in d0 is set.

(This will work for the 68000, I'm not too sure about the 6800, googling tells me that BITA or BITB instructions might be of use: http://www.textfiles.com/programming/CARDS/6800 )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文