链接列表实现ARM7

时间:2015-04-06 17:46:12

标签: linked-list arm arm7

我目前正在使用Keil uVision4,我正在尝试实现一个链接列表,该列表将通过预设列表,并且仅在它到达结尾时停止,或者它找到与寄存器r0中的值匹配的值。我调试了我的代码并注意到在循环的第一次运行期间,初始LDR r0,[r0]将值存储在r0中的第一个节点内,但是在第二次进入循环时,它会加载当执行LDR r0,[r0]时,0x00000000进入r0。我试图找出它如何进入列表中的下一个节点而不是返回零值。

    AREA question1, CODE, READONLY
    ENTRY
    ;--------------------------------------------------------------------------
        LDR r1, =0x12347777
        ADR r0, List            ;r0 points to the first element in list
Loop    LDR r4, [r0]            ;places the next pointer in r0
        CMP r0, r1
        LDR r0, [r0, #4]
        BEQ Store
        CMP r0, #0x00           ;checks if it is the end of the linked list
        BNE Loop                ;if its not the end of the list, then     continue reading the next node

        LDR r2, =0xF0F0F0F0     ;Failure, set register r2
        B fin

Store   MOV r2, #0xFFFFFFFF     ;Success, set register r2
        LDR r3, [r0]            ;Success, store pointer in r3

fin     B fin

; ---------------------------------------------- -----------------------------

        AREA question1, DATA, READWRITE

List  DCD 0x12341111, Item5
Item2 DCD 0x12342222, Item3
Item3 DCD 0x12343333, Item4
Item4 DCD 0x12344444, Item6
Item5 DCD 0x12345555, Item2
Item6 DCD 0x12346666, Item7
Item7 DCD 0x12347777, 0x00      ;terminator
;---------------------------------------------------------------------------
        END

0 个答案:

没有答案