Algorithm 装配中的Fletchers算法

Algorithm 装配中的Fletchers算法,algorithm,assembly,arm,cortex-m,Algorithm,Assembly,Arm,Cortex M,在discoboard(ARM7)上,我试图从实现fletcher的算法,输入是单个32位字 无法实现fletcher的32位版本,因为它需要将大量数据加载到内存中,因此: 我将32位字拆分为2个16位半字,然后运行fletcher-16算法 然而,输出总是数字的总和,这在我看来是非常错误的 例如 预期产出: Checksum value 实际产出: The sum of the 2 16 bit half words. Wut 如果这是实际的算法,或者我犯了错误,有人能帮忙吗 @ Inpu

在discoboard(ARM7)上,我试图从实现fletcher的算法,输入是单个32位字

无法实现fletcher的32位版本,因为它需要将大量数据加载到内存中,因此:

我将32位字拆分为2个16位半字,然后运行fletcher-16算法

然而,输出总是数字的总和,这在我看来是非常错误的

例如

预期产出:

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

谢谢大家!

从链接的维基百科页面:

通常,第二个和将乘以2^16,并添加到 简单的校验和,有效地将校验和并排堆叠在一个 32位字,其简单校验和至少在有效端


您的代码似乎在计算两个16位校验和,但不会根据需要将第二个校验和移位16位。

您是说armv7?是的,抱歉@old_timer这很有意义。谢谢!:)
@ 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