0

I am currently using Keil uVision4 and I am trying to implement a linked list that will go through a preset list and stop only when it either reaches the end or it finds a value that matches what is in register r0. I have debugged my code and noticed that during the first run through of the loop, the initial LDR r0, [r0] stores the value inside the first node in r0, but in the second time it comes to go through the loop, it loads 0x00000000 into r0 when it executes LDR r0, [r0]. I'm trying to figure out how it can go to the next node in the list rather than return a zero value.

    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
Mike Blair
  • 1,821
  • 2
  • 11
  • 11
  • You're watching the values in the registers as you debug, right? When do they start looking wrong? Hint: where do you load the actual _address_ of the next list item? – Notlikethat Apr 06 '15 at 17:57
  • I just noticed that I'm getting an error 65: access violation at (some address) : no 'read' permission when it goes into the loop for the second time at the second execution of LDR r0, [r0] could that be the issue" – Mike Blair Apr 06 '15 at 18:07
  • Ahh, figured it out, I've posted what I have come up with. Thanks for the tip. – Mike Blair Apr 06 '15 at 18:21

0 Answers0