-2

Why is line 2 i * 8? I got this code from a book.

MOV X9,XZR // i = 0
loop1: LSL X10,X9,#3 // X10 = i * 8
ADD X11,X0,X10 // X11 = address of array[i]
STUR XZR,[X11,#0] // array[i] = 0
ADDI X9,X9,#1 // i = i + 1
CMP X9,X1 // compare i to size
B.LT loop1 // if (i < size) go to loop1
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Connor
  • 1
  • 1
  • The `lsl` is like a binary exponent. So `lsl 3` is the same as `* 2 ^ 3` or multiply by 8. The reason for 8 is that you have a 64 bit clear or 8 bytes at a time with `stur`. – artless noise Jan 13 '21 at 12:49
  • x10 = x9 << 3, which means multiply by 8 – old_timer Jan 13 '21 at 15:37
  • I dont remember my vhdl specifically but it is on par with this pseudocode x10[31 downto 3] = x9[28 downto 0] and x10[2 downto 0] = 0 – old_timer Jan 13 '21 at 15:38

1 Answers1

2

LSL is logical shift left. Numbers are binary. One shift doubles the number. So three shifts is two to the third power which is 8.

matt
  • 515,959
  • 87
  • 875
  • 1,141