汇编中的 Fletcher 算法
Fletchers algorithm in Assembly
在 discoboard (ARM7) 上,我试图从 https://en.wikipedia.org/wiki/Fletcher%27s_checksum 实现弗莱彻算法,输入是单个 32 位字。
无法实现 32 位版本的 fletcher,因为它需要将大量数据加载到内存中,因此:
我将 32 位字拆分为 2 个 16 位半字,然后 运行 fletcher-16 算法。
但是,输出总是数字的总和,这对我来说似乎是错误的。
例如,
Input: 0x1b84ccc / 1101110000100110011001100
预期输出:
Checksum value
实际输出:
The sum of the 2 16 bit half words. Wut
如果这是实际算法,有人能帮忙吗?还是我犯了错误?
@ Input:
@ r0: 32 bit message
@ Output:
@ r0: checksum value
fletchers_checksum:
push {r1-r4,lr}
mov r3, #0 @ store the sum
mov r4, r0 @ store message
@split to 2 16 bit messages:
@@take frequency
ldr r1, =#0xFFFF0000
and r0, r1, r4
lsr r0, #16
bl compute_checksum_for_16_bit_number
@@amplitude
ldr r1, =#0xFFFF
and r0, r1, r4
bl compute_checksum_for_16_bit_number
mov r0, r3
pop {r1-r3,lr}
bx lr
compute_checksum_for_16_bit_number:
push {lr}
ldr r1, =#65536
add r0, r3 @add current sum to it.
bl mod
mov r3, r0 @store new sum
pop {lr}
bx lr
谢谢!
来自链接的维基百科页面:
Usually, the second sum will be multiplied by 2^16 and added to the
simple checksum, effectively stacking the sums side-by-side in a
32-bit word with the simple checksum at the least significant end.
您的代码似乎计算了两个 16 位校验和,但没有按要求将第二个校验和移动 16 位。
在 discoboard (ARM7) 上,我试图从 https://en.wikipedia.org/wiki/Fletcher%27s_checksum 实现弗莱彻算法,输入是单个 32 位字。
无法实现 32 位版本的 fletcher,因为它需要将大量数据加载到内存中,因此:
我将 32 位字拆分为 2 个 16 位半字,然后 运行 fletcher-16 算法。
但是,输出总是数字的总和,这对我来说似乎是错误的。
例如,
Input: 0x1b84ccc / 1101110000100110011001100
预期输出:
Checksum value
实际输出:
The sum of the 2 16 bit half words. Wut
如果这是实际算法,有人能帮忙吗?还是我犯了错误?
@ Input:
@ r0: 32 bit message
@ Output:
@ r0: checksum value
fletchers_checksum:
push {r1-r4,lr}
mov r3, #0 @ store the sum
mov r4, r0 @ store message
@split to 2 16 bit messages:
@@take frequency
ldr r1, =#0xFFFF0000
and r0, r1, r4
lsr r0, #16
bl compute_checksum_for_16_bit_number
@@amplitude
ldr r1, =#0xFFFF
and r0, r1, r4
bl compute_checksum_for_16_bit_number
mov r0, r3
pop {r1-r3,lr}
bx lr
compute_checksum_for_16_bit_number:
push {lr}
ldr r1, =#65536
add r0, r3 @add current sum to it.
bl mod
mov r3, r0 @store new sum
pop {lr}
bx lr
谢谢!
来自链接的维基百科页面:
Usually, the second sum will be multiplied by 2^16 and added to the simple checksum, effectively stacking the sums side-by-side in a 32-bit word with the simple checksum at the least significant end.
您的代码似乎计算了两个 16 位校验和,但没有按要求将第二个校验和移动 16 位。