Using pointer to access array instead of index
see MSP430 coding example below.
uint8_t parity = ;
uint8_t index = ;
//flag
gMUXTask.responseData[index++] = MUX_DATA_BIT_LOW;
//dirty
gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.dirty;
parity += gDeviceStatus.responseStatus.dirty;
//smoke alarm
gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.smokeAlarm;
parity += gDeviceStatus.responseStatus.smokeAlarm;
//high temperature
gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.highTemperature;
parity += gDeviceStatus.responseStatus.highTemperature;
//low temperature
gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.lowTemperature;
parity += gDeviceStatus.responseStatus.lowTemperature;
//miss Head
gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.missHead;
parity += gDeviceStatus.responseStatus.missHead;
//parity
gMUXTask.responseData[index++] = CalcParity(isOddAlgorithm(false), parity);
//outputState
gMUXTask.responseData[index++] = MUX_DATA_BIT_LOW;
The ASM code generated is below, it is around 120bytes.
Another example here,
uint8_t* p = gMUXTask.responseData;
*p++ = MUX_DATA_BIT_LOW;
//dirty
*p++ = gDeviceStatus.responseStatus.dirty;
parity += gDeviceStatus.responseStatus.dirty;
//smoke alarm
*p++ = gDeviceStatus.responseStatus.smokeAlarm;
parity += gDeviceStatus.responseStatus.smokeAlarm;
//high temperature
*p++ = gDeviceStatus.responseStatus.highTemperature;
parity += gDeviceStatus.responseStatus.highTemperature;
//low temperature
*p++ = gDeviceStatus.responseStatus.lowTemperature;
parity += gDeviceStatus.responseStatus.lowTemperature;
//miss Head
*p++ = gDeviceStatus.responseStatus.missHead;
parity += gDeviceStatus.responseStatus.missHead;
//parity
*p++ = CalcParity(isOddAlgorithm(false), parity);
//outputState
*p++ = MUX_DATA_BIT_LOW;
The ASM code generated, it is about 106 bytes.
Using pointer to access an array which has a better performance.
Using pointer to access array instead of index的更多相关文章
- C lang:Pointer and multidimensional array
Xx_Introduction Double indrection:Address of Address;Pointer of Pointer Ax_Code #include<stdio.h& ...
- java数据结构--线性结构
一.数据结构 数据结构由数据和结构两部分组成,就是将数据按照一定的结构组合起来,这样不同的组合方式有不同的效率,可根据需求选择不同的结构应用在相应在场景.数据结构大致 分为两类:线性结构(如数组,链表 ...
- Go: using a pointer to array
下面的不是指针指向数组,而是指针指向Slice I'm having a little play with google's Go language, and I've run into someth ...
- c pointer and array
Pointer: A pointer is a variable that contains the address of a variable. if c is a char and p is a ...
- Twitter OA prepare: Equilibrium index of an array
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to ...
- Array类
class Array Arrays are ordered, integer-indexed collections of any object. Array indexing starts at ...
- 【题解】【数组】【查找】【Leetcode】Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- Return array from functions in C++
C++ does not allow to return an entire array as an argument to a function. However, you can return a ...
- golang ----array and slice
Go Slices: usage and internals Introduction Go's slice type provides a convenient and efficient mean ...
随机推荐
- 八. Python基础(8)--函数
八. Python基础(8)--函数 1 ● 函数返回布尔值 注意, 自定义的函数也可以是用来作逻辑判断的, 例如内置的startswith()等函数. def check_len(x): ' ...
- java中各种运算符的优先级
最高级 1: var++和var-- 2:+ .- .(正负号,非加减).++var.--var 3:(type)强制转换 4:!(非) 5:*./.%. 6:+.-(加减运算) 7:<= .& ...
- 火狐下,td 的 bug;
想实现类似的效果,看代码, <div style="width:488px;float:left; margin:-52px 0px 15px 15px;"> < ...
- libusb示例
#include <stdio.h> #include <libusb-1.0/libusb.h> #include <stdint.h> #include < ...
- python操作sqlite3的几项问题分析
不同数据库还是有各自特点的,之前自以为熟悉mysql,然后全都照搬到sqlite3上,这样果然是不行的.笔者就近期在使用sqlite3时碰到的问题做了总结分析,并给出相应解决方法,供大家参考. 1.如 ...
- 【Python】多进程-队列
#练习:队列 from multiprocessing import Process, Queue def offer(queue): # 入队列 queue.put("Hello Worl ...
- LVM逻辑卷
LVM逻辑卷 一.LVM逻辑卷概述 1.LVM的作用: 扩充磁盘:不动数据,在使用状态,将磁盘容量变大. 能把多个物理的磁盘整合成一张大的虚拟的磁盘,比如:有3个5G的磁盘,能把它们整合成一个15G的 ...
- Oracle自我补充之OVER()函数介绍
OVER(PARTITION BY)函数介绍 开窗函数 Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...
- MySQL中的运算符和时间运算
一.MySQL中运算符的分类 算术运算符,比较运算符,逻辑运算符,按位运算符 二.算数运算符 符号 作用 + 加法 - 减法 * 乘法 ...
- 关于Linux前后台进程切换
前言: 当使用SSH远程登录服务器时,对于运行时间较长的程序(如Caffe的训练可能需要十几个小时), SSH可能会在很长时间后断掉,导致程序没运行完就中断了. 为了解决这个问题,需要将在服务器运行的 ...