Reputation: 349
I'm learning ARMASM in KEIL uVision 5 using the LPC1768 architecture and the simulator using debugging in the IDE. I wanted to write an assembly program which will find the minimum value in any array. Here's the first code that I've written:
area pgrm, code, readonly
export __main
end_array dcd 0xffffffff
__main
ldr r0, =list
ldr r1, [r0]
ldr r3, end_array
find_min
add r0, #4
ldr r2, [r0]
cmp r2, r3
beq stop
cmp r1, r2
movgt r1, r2
b find_min
stop b stop
area pgrmdata, data, readwrite
; Defining an array
list dcd 4, 20, 3, 10, 100, 3, 4, 0xffffffff
end
But it wasn't working at all. The registers 1 and 2 were not being loaded with any values even if the program was running and registers r0 and PC were being incremented forever.
Then after hours of trial and error I happend to change the pgrmdata
section attribute of READWRITE
to READONLY
. Now the changed code looks like this:
area pgrmdata, data, readonly
; Defining an array
list dcd 4, 20, 3, 10, 100, 3, 4, 0xffffffff
end
The code works perfectly fine now. I don't understand why this section being readonly or read and writeable even matters and why the latter attribute is running the program but not updating the registers at all.
Also, I know that these codes will work:
area pgrm, code, readonly
export __main
end_array dcd 0xffffffff
list dcd 4, 20, 3, 10, 100, 3, 4, 0xffffffff
__main
ldr r0, =list
ldr r1, [r0]
ldr r3, end_array
find_min
add r0, #4
ldr r2, [r0]
cmp r2, r3
beq stop
cmp r1, r2
movgt r1, r2
b find_min
stop b stop
end
and
area pgrm, code, readonly
export __main
end_array dcd 0xffffffff
__main
ldr r0, =list
ldr r1, [r0]
ldr r3, end_array
find_min
add r0, #4
ldr r2, [r0]
cmp r2, r3
beq stop
cmp r1, r2
movgt r1, r2
b find_min
stop b stop
area pgrm, data, readonly
; Defining an array
list dcd 4, 20, 3, 10, 100, 3, 4, 0xffffffff
end
These work because in the first one the data is in the same section and in the second one the linker merges both the sections to one because I've given them both the same name (but my instinct says that this is something I shouldn't generally do). Am I missing something here? It'll help me a lot if you can link me some resources to learn about NXP LCP1768 ARMASM and also general assembly. Thanks.
I noticed that even the r1
register is not loading in the right memory address for the list.
Upvotes: 1
Views: 72