/* -------------------------------------------------- Use this file to teach: Get the values in A[4], A[k] into a reg Store the value in a r0 in A[4], A[k] -------------------------------------------------- */ .global main, Stop, CodeEnd .global DataStart, DataEnd .global A, i .text main: movw r1, #:lower16:A movt r1, #:upper16:A // r1 = base address of array A movw r2, #:lower16:i movt r2, #:upper16:i // r2 = address of i ldr r2, [r2] // r2 = i (offset needed = i*4) add r2, r2, r2 // r2 = i*2 add r2, r2, r2 // r2 = i*4 // Address of A[i] = base addr + i*4 bytes ldr r0, [r1, r2] // Load A[i] into r0 Stop: CodeEnd: nop /* -------------------------------------------- Begin of the permanent program variables -------------------------------------------- */ .data DataStart: A: .4byte 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 // array .align 2 i: .4byte 5 DataEnd: .end