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 ...
随机推荐
- Dll重定向(尚存否?)
windows核心编程(第五版)的20.6节介绍了Dll重定向. 0x01 Dll重定向简介 产生Dll重定向原因: 应用程序 a.exe 依赖动态链接库 compoent.dll 1.0 版本.但 ...
- js 变量的声明能提升 初始化不会提升
var x = 5; // 初始化 x elem = document.getElementById("demo"); // 查找元素 elem.innerHTML = x + & ...
- LeetCode 151 翻转字符串里的单词
题目: 给定一个字符串,逐个翻转字符串中的每个单词. 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 ...
- 谷歌开源的TensorFlow Object Detection API视频物体识别系统实现(二)[超详细教程] ubuntu16.04版本
本节对应谷歌开源Tensorflow Object Detection API物体识别系统 Quick Start步骤(一): Quick Start: Jupyter notebook for of ...
- spring源码研究2 自定义标签实现及使用
1.自定义标签实现及使用参考: http://blog.csdn.net/fighterandknight/article/details/50112701 1)创建一个需要扩展的组件 User.ja ...
- EF code first Mysql 更换主键类型
把主键从long 改为int 居然要删掉重建,不知道有没有更好的办法. 删除带外键的表: Add-Migration name 修改生成的文件,主要把dbo.删除 然后update-database
- select标签的相关操作,选中,获取option的值,二级联动
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- random_select
package sorttest; //expected and worst running time is O(n),asuming that the elements are distinct ...
- 12.输入一个成绩计算其A,B,C,D,E等级
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int score; s ...
- Spring Boot 揭秘与实战(二) 数据存储篇 - 数据访问与多数据源配置
文章目录 1. 环境依赖 2. 数据源 3. 单元测试 4. 源代码 在某些场景下,我们可能会在一个应用中需要依赖和访问多个数据源,例如针对于 MySQL 的分库场景.因此,我们需要配置多个数据源. ...