c++ - 你能在 Arduino (C/C++) 中生成 128 位无符号整数吗?

标签 c++ c arduino

我正在使用 uint 来存储位序列,并希望存储 128 的位序列。我计划使用循环位旋转来循环遍历它们。有什么好的方法可以生成 128 位整数吗?如果不是,下一个可以轻松“循环移位”的最佳方法是什么?

我需要它快速运行,因为它会在中断中发生。大约每 250 微秒一次。

最佳答案

使用 char[16] 数组,并在汇编中而不是 C 中编写关键的移位代码,因为 C 没有很好的方法让您从一个转变。

你应该可以做类似的事情

ldi r29, hi8(array) ; Load Y register
ldi r28, lo8(array) ; (16 bits)
ldi r22, 16         ; Loop counter
ldd r23, Y+15       ; Get the last byte
lsl r23             ; And put the last bit into the carry flag
loop:               ;   so it will be shifted into the first bit
ld r23, Y           ; Load from array into r23
rol                 ; Rotate left through carry
st Y+, r23          ; Store it back and increment Y
dec r22             ; Decrement loop counter
brne loop           ; Loop if not done

进行旋转,但这是未经测试的,我也不是 AVR 组装高手。 dec 是特殊的,不会干扰进位标志,因此它在循环中安全保存。

关于c++ - 你能在 Arduino (C/C++) 中生成 128 位无符号整数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33675737/

相关文章:

c++ - 在 boost-spirit 中,有没有办法通过函数调用创建语法以减少代码?

c - HPC中的UPC-经验和建议

python - 通过TCP从arduino发送数据到python

c - 如何将数学表达式转换为C语句?

c - C的单元测试框架

python - 从 Arduino C 到 Raspberry pi python - 线程内的 volatile 变量访问

java - 用 Java 控制 Arduino

c++ - 如何重新分配全局变量c++

c++ - 使用右值引用延长临时对象的生命周期

c++ - 对 map 容器使用remove_if