C166 8位字节位运算赋值-代码优化

8位字节位运算赋值优化特记录下:

 

unsigned short func1()
{
unsigned short a;
return a;
}

unsigned char func2()
{
unsigned char a;
return a;
}

unsigned short u_16;
unsigned char u_8;

void sub_027F08()
{
UINT8 t8u;

// ERAM_u16_81F48 = ((sub_035EC8() == 0) & 1) <<14 | (ERAM_u16_81F48 & (~(1<<14)));
// ERAM_u8_81F64 = (FDC_INT8U)(((FDC_INT8U)sub_032AE4() != 0) & 1) << 6 | (FDC_INT8U)(ERAM_u8_81F64 & (~(1<< 6)));
u_16 = ((func1() == 0) & 1)<<14 | (u_16 & (~(1<<14)));
// u_8 = ((func1() == 0) & 1)<<14 | (u_8 & (~(1<<14)));

t8u = (func1() == 0) ? (UINT8)1: (UINT8)0;
t8u &= 1;
t8u <<= 6;
u_8 =(UINT8)t8u | (UINT8)(u_8 & (UINT8)(~(1<<6)));

return;
}

结果如下:

1264: t8u = (func1() == 0) ? (UINT8)1: (UINT8)0;
00027F34 DA02087F CALLS func1(0x27F08)
00027F38 E10A MOVB RL5,#0x00
00027F3A 4840 CMP R4,#0
00027F3C 3D01 JMPR CC_NZ,0x027F40
00027F3E E11A MOVB RL5,#0x01
1265: t8u &= 1;
00027F40 69A1 ANDB RL5,#1
1266: t8u <<= 6;
00027F42 5C65 SHL R5,#0x06
1267: u_8 =(UINT8)t8u | (UINT8)(u_8 & (UINT8)(~(1<<6)));
1268:
00027F44 F3F8D805 MOVB RL4,DPP0:0x05D8
00027F48 67F8BF00 ANDB RL4,#0x00BF
00027F4C 718A ORB RL4,RL5
00027F4E F7F8D805 MOVB DPP0:0x05D8,RL4
1269: return;
00027F52 DB00 RETS

转载于:https://www.cnblogs.com/xihong2014/p/10099470.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值