Presentation is loading. Please wait.

Presentation is loading. Please wait.

ARM Memory.

Similar presentations


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

1 ARM Memory

2 Sections Programs = Code Data

3 Sections Compiled program stored in sections
.text : Executable code read/executable .rodata : Read Only Data read .data : Data read/write .bss : Uninitialized Data read/write

4 Sections Compile C++

5 Sections Sections placed in memory for execution:

6 Identifiers Identifier: Names the memory address of next thing IDENTIFIER: code or IDENTIFIER: code

7 Data Directives .word X Store 32 bit value X in memory
.space X Reserve X bytes in memory

8 Simplified .data Things to place into memory after code .text Code

9 Same Segment Access LDR : Load Register LDR rd, identifier
Pseudo instruction LDR rd, identifier Load value at identifier

10 Same Segment Access Can place data in .text
Make sure doesn’t get executed!!!

11 Same Segment Access Fun Fact LDR :
Calculates location as currentLocation immediate C ( ) (2010)

12 Same Segment Access Fun Fact LDR :
Calculates location as currentLocation immediate ( ) C (10810) C

13 LDR Immediate LDR rd, =longConstant Puts immediate at end of .text
Automatically loads that address

14 Cross Segment Access Can not directly load identifier in other segment
Jump may be too big to specify with bits we have

15 Cross Segment Access LDR rd, =identifier Load address of identifier

16 Cross Segment Access LDR rd, =identifier Load address of identifier

17 How It Works Fun Fact LDR rd, =identifier
Stores address of target at end of current .text Calculates location as current offset C ( ) (2010) Loads real address from that location

18 Cross Segment Access LDR rd, [rs]
Load value at the address stored in rs

19 Cross Segment Access LDR rd, [rs] : always second step
First load address into rs Then load data from that address

20 STR STR rs, [rd] Store value from rs to address in rd
NOTE: Reverse order of operands

21 STR Notes Process: Load address in register Store other register to that address

22 LDR/STR Summary & Guidelines
Store all data in .data section Use two steps Load: Load address Load data at address Store: Load address Store data to address

23 LDR Variants LDR rd, identifier LDR rd, [rs] LDR rd, =identifier
LDR r1, x LDR r3, [r2] Load value at identifier Same section only Load value at address in rs LDR rd, =identifier LDR rd, =immediate LDR r2, =x LDR r3, =0x1234ABCD Load address of identifier Put constant into .text; Load that constant

24 Words vs Bytes

25 Memory Address Word = 32 bits = 4 bytes
Word addresses = multiples of 4 C = 1210 10 = 1610 14 = 2010

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

27 Memory Address Bytes in word numbered right to left 1000 = 64
1005 = 89 100F = 81 1010 = 81 +11 +10 +9 +8 +15 +14 +13 +12 +3 +2 +1 +0 +7 +6 +5 +4

28 Other Memory Directives
.byte : Store 8 bit value .hword : Store 16 bit value (half-word)

29 Alignment .word should be at multiple of 4 .hword should be at multiple of 2 .byte anywhere BAD Alignment: D = 13!!!

30 Align .align : pad with 0’s until next word boundary

31 Alignment Tips Load/Store to unaligned address = silent failure!
Unneeded .align’s ignored When in doubt, .align

32 Byte Packing Byte packing : ordering class/struct members for proper alignment

33 Load/Store Bytes LDRB rd, [rs] STRB rs, [rd]
Load one byte from address rs into rd STRB rs, [rd] Store value in rs to address in rd

34 Sign Issues 34 + -1 = 289???? -1 as byte = 0xFF
0xFF as 32 bit value = 255 = 289????

35 Sign Extension LDRSB rd, [rs]
Load one byte from address rs into rd; extend sign bit


Download ppt "ARM Memory."

Similar presentations


Ads by Google