我正在使用 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/