Talk:LDR

From ARMwiki
(Difference between revisions)
Jump to: navigation, search
(Reply to NoctiLucent; nicer formatting)
Line 1: Line 1:
Under "Immediate Offset" explanation you say: ""R3 points to the structure base, you can load the third element with: "", but I think it should read "eigth element". If not, you need to explain why. Then also the C equivalence for the same should read either:
+
==LDR offsets==
a) "r0 = r1[4];"  OR
+
Under "Immediate Offset" explanation you say: ""R3 points to the structure base, you can load the third element with: "", but I think it should read "eigth element". If not, you need to explain why. Then also the C equivalence for the same should read either:<br>
b) "r0 = r1[3]; (as C arrays uses 0 as index 1)"
+
a) "r0 = r1[4];"  OR<br>
 +
b) "r0 = r1[3]; (as C arrays uses 0 as index 1)"<br>
 
[[User:NoctiLucent|NoctiLucent]] 20:18, 6 March 2012 (CET)
 
[[User:NoctiLucent|NoctiLucent]] 20:18, 6 March 2012 (CET)
 +
 +
:Thank you for your comments. The reason why <code>LDR R0, [R3, #8]</code> loads the ''third'' element of the array (the third word) is that the offset given is specified in bytes; thus the first word is offset #0, the second #4, and #8 would be the third.<br>
 +
:Likewise with the C equivalence, the ARM instruction <code>LDR R0, [R1, #4]</code> is asking that we load the second word (offset +4 bytes) from the array indicated, thus the equivalent <code>r0 = r1[1];</code> is correct.<br>
 +
:I shall edit the page to make this clearer.<br>
 +
:[[User:Admin|Rick]] 05:18, 7 March 2012 (CET)

Revision as of 06:18, 7 March 2012

LDR offsets

Under "Immediate Offset" explanation you say: ""R3 points to the structure base, you can load the third element with: "", but I think it should read "eigth element". If not, you need to explain why. Then also the C equivalence for the same should read either:
a) "r0 = r1[4];" OR
b) "r0 = r1[3]; (as C arrays uses 0 as index 1)"
NoctiLucent 20:18, 6 March 2012 (CET)

Thank you for your comments. The reason why LDR R0, [R3, #8] loads the third element of the array (the third word) is that the offset given is specified in bytes; thus the first word is offset #0, the second #4, and #8 would be the third.
Likewise with the C equivalence, the ARM instruction LDR R0, [R1, #4] is asking that we load the second word (offset +4 bytes) from the array indicated, thus the equivalent r0 = r1[1]; is correct.
I shall edit the page to make this clearer.
Rick 05:18, 7 March 2012 (CET)
Personal tools
Namespaces

Variants
Actions
Navigation
Contents
Toolbox