Presentation is loading. Please wait.

Presentation is loading. Please wait.

ARM Arrays.

Similar presentations


Presentation on theme: "ARM Arrays."— Presentation transcript:

1 ARM Arrays

2 Arrays Array: Block of contiguous values at a known starting address
0x1000 86 0x1004 95 0x1008 73 0x100C 87 0x1010 79 0x1014 98

3 Arrays Array: Indexed location calculated as: base address + index * elementSize Array[0] 0x1000 86 Array[1] 0x1004 95 Array[2] 0x1008 73 Array[3] 0x100C 87 Array[4] 0x1010 79 Array[5] 0x1014 98 Array[3] 0x * 4 0x C (12) 0x1012

4 Declaring An Array Array: Block of contiguous values at a known starting address

5 Little Endian Reminder
Bytes in word numbered right to left aka “Little Endian” 1000 = 64 1001 = FF 1003 = 00 1012 = 81 +3 +2 +1 +0

6 Little Endian Array of 4 bytes loaded differently than a word:

7 Array Basics Always need to load array address

8 Array Basics Array[0] = Value at array address

9 Array Basics Array[1] = Value at (array address + element size)
4 bytes

10 Array Basics Array[2] = Value at (array address + 2 * element size)

11 LDR Trick LDR rd, [rn, #immediate] : Calculate rn + immediate
Get value at that memory address into rd

12 Array With Trick Access as baseAddress + offset

13 Array Basics With Bytes
Always need to load array address

14 Array Basics With Bytes
Load elements as bytes or signed bytes Store as bytes

15 Array Basics With Bytes
Array[x] = Value at (array address + x * element size) Element size = 1 byte

16 Array Loops

17 Basic Loop Must Know Keep track of: Size of Array Array Size
Current Location Index Total

18 Basic Loop Test compares Array Size Index

19 Basic Loop Body uses Current Location Total

20 Basic Loop Update changes Current Location Index

21 Basic Loop Keep track of: Array Size Current Location Index Total

22 Basic Loop Issue Lose track of base address

23 Better Loop LDR rd, [rn, rm] : Calculate rn + rm
Get value at that memory address into rd

24 Better Loop Keep track of: Array Size Base Address Index Total
Offset Into Array

25 Better Loop Indexed Address using Base Address Offset Into Array

26 Better Loop Update Index Offset Into Array Leave baseAddress intact!

27 Best Loop LDR rd, [rn, rm, lsl #x] : Indexed Address
Calculate rn + rm * 2x Get value at that memory address into rd

28 Best Loop Keep track of: Array Size Base Address Index Total

29 Best Loop Indexed Address using
Base Address Index Calculate element Location as base + index * size r2 + r3 * 4 Assuming 4 byte data No LSL if accessing byte data!

30 Copy Array Start with Keep Track of Empty Space Array Size
Original Base Address Empty Base Address Index

31 Copy Array Indexed Addresses Read from Write to
Original Base Address + 4 * Index Write to Empty Base Address + 4 * Index

32 Strings

33 C-String C-String: Character array Ends with null char '\0' or 0
Char = byte Ends with null char '\0' or 0 Cstring[0] 0x1000 41 (A) Cstring[1] 0x1001 70 (p) Cstring[2] 0x1002 Cstring[3] 0x1003 6c (l) Cstring[4] 0x1004 65 (e) Cstring[5] 0x1005 00

34 Strings .ascii : allocate array of bytes
.asciz : allocate null terminated array of bytes

35 String Loop – Count e's Start with Null terminated string
Keep Track of NumberE's Base Address Index Current Char

36 String Loop – Count e's Test Get next char if != 0, continue
Indexed Address base + index

37 String Loop – Count e's Body r4 has current
Conditionally Increment NumberE's

38 String Loop – Count e's Update Increment Index


Download ppt "ARM Arrays."

Similar presentations


Ads by Google