//online parser:
https://www.bccn.net/run/
#include <stdio.h>
typedef unsigned char reg;
#define BIT_MASK4
(reg)0xEF
#define BIT_CLR567
(reg)0x1F
#define BIT_SET567(_r)
(reg)(_r & 0xE0)
#define BIT_MASK4SR(_r, _c)
(reg)((_r & BIT_CLR567) >> _c)
#define BIT_BAOBAO(_r, _c)
(reg)(BIT_SET567(_r) | BIT_MASK4SR(_r, _c))
#define FR_FLAG
#define BIT4
(reg)(1 << 2)
#define BIT_CLRX(_idx)
(reg)(0xFF >> (_idx - 1))
#define BIT_SETX(_r, _idx)
(reg)(_r & (0xFF << (_idx + 1)))
#define BIT_MASKXSR(_r, _idx, _c)
(reg)((_r & BIT_CLRX(_idx)) >> _c)
#define BIT_FR(_r, _idx, _c)
(reg)(BIT_SETX(_r,_idx) | BIT_MASKXSR(_r, _idx, _c))
int main(int argc, char *argv[])
{
reg r, *vreg = (char *)main;
for (int i = 0; i < 125; i++) {
r = vreg[i];
#ifndef FR_FLAG
printf("%02d: r = 0x%x, r(%d) = 0x%x\n",
(i + 1), r, 2, BIT_BAOBAO(r, 2));
#else
printf("%02d: r = 0x%x, r(%d) = 0x%x\n",
(i + 1), r, 2, BIT_FR(r, BIT4, 2));
#endif
}
return 0;
}
[此贴子已经被作者于2021-8-22 14:23编辑过]