0

从 m/m 位置 2500H 存储了 N 个字节。N 的值存储在 2400H 中。我怎样才能编写一个 8085 程序来将所有字节的位 Di 与 Dj 互换(无论位值如何)。i=4 和 j=0 的值

4

1 回答 1

0

没有人愿意为你做功课。话虽如此,这就是如何将 1 字节数据的第 i 位与第 j 位互换的方法。

首先让我们回顾一下按位逻辑运算符及其用法。假设我们想知道第 4 位是否被设置,我们需要一个位掩码0000 1000 (即08H)并将AND其与数据一起使用。为了清除第二位,我们使用位掩码1111 1101(即FDH)和AND数据。然而,要设置第 6 位,我们需要一个位掩码0000 0010(即02H)和OR数据。为了补充翻转第 4 位,我们采用位掩码0000 1000 (即08H)并将XOR其与数据一起使用。

假设实际数据在寄存器 D 中,因此为了将第 2 位与第 4 位交换,我们可以这样写:

MVI A, 08H    ;i-th bit
ORI 02H       ;j-th bit
ANI D         ;only 2nd and 4bit of the data survives
JPE SKIP      ;if both bits are same (both 0 or both 1) no exchange required
;if not we need a swap, which is this case can be done by flipping the both 
MOV A,D       ;bring back the data again
XRI 08H       ;flip the i-th bit
XRI 02H       ;flip the j-th bit
SKIP: MOV D,A ;put the data back to D

位掩码可以通过适当数量的移位(或无进位循环)以编程方式生成。对所有字节重复此过程n将完成所需的任务。

于 2021-06-21T09:08:59.253 回答