1

I have the following assembly code:

alpha: .space 64    @reserves 64 bytes
i: int 0
   .text
   .align2
   .globalmain
   .func main
main:
      ldr r3,=i      @r3 is address of i
      mov r2,#0      @r2 is 0
      str r2,[r3]    @r2 is stored in r3
L1:
    ldr r3,=i             @r2 is address of i
    ldr r2,[r3]           @r2 is now address of i 
    cmp r2,#16            
    bge exit              @if r2 > 16, then exit (but it is not)
    ldr r3,=i             @r3 is address of i
    ldr r2,[r3]           @r2 is address of i
    add r1,r2,#0x200      @r1 is r2 + 0x200
    ldr r3,=alpha         @r3 is address of first element in array alpha (I think)
    str r1,[r3,r2,asl#2]
    ...

I know its alot, but I only have trouble with one part. I commented the parts I do know, or at least I think I know.

The trouble I'm having is with str r1,[r3,r2,asl#2]. I know asl#2 is a left shift, but that's all I really know. Where does r1 get stored, in r3? What would be the result of the str command? Can someone explain it for me?

buydadip
  • 8,890
  • 22
  • 79
  • 154
  • 1
    Does [this help](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/BABFGBDD.html)? – Weather Vane Feb 03 '16 at 20:52
  • 1
    Possible duplicate of [Explanation of str in ARM assembly](http://stackoverflow.com/questions/35310272/explanation-of-str-in-arm-assembly) – Notlikethat Feb 10 '16 at 09:02
  • Yes, because _you asked the exact same question twice_ (but the other one is clearer and has better answers). – Notlikethat Feb 10 '16 at 09:04
  • indeed I did. I entirely forgot about this – buydadip Feb 10 '16 at 09:05
  • @artlessnoise My impression is that we prefer to keep open the question which was asked _best_: http://meta.stackoverflow.com/q/251938/3156750 – Notlikethat Feb 10 '16 at 20:36
  • @Notlikethat Best is subjective; I have no idea why the other answers got more votes. It is not significantly better/different imo. Probably neither will be closed. – artless noise Feb 11 '16 at 14:18

1 Answers1

1
str r1,[r3,r2,asl#2]

value in r2 is arithematic left shifted by (immediate value) 2 and is added to the contents of r3 , to get the memory address at which r1 will be stored.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
c_mnon
  • 366
  • 4
  • 14
  • 1
    Or in 'C' it would be like `int r3[]; r3[r2]=r1;` -- `asl #2` for 32bit sized arrays and `asl #1` is common for 16bit arrays (or shorts). – artless noise Feb 04 '16 at 04:35