CHAPTER 18. ARRAYS CHAPTER 18. ARRAYS
DCD ||.conststring||+0x32
DCD ||.conststring||+0x3c
DCD ||.conststring||+0x44
DCD ||.conststring||+0x4d
The address of the table is loaded in R1. All the rest is done using just oneLDRinstruction. Then input valuemonthis
shifted left by 2 (which is the same as multiplying by 4), then added to R1 (where the address of the table is) and then a
table element is loaded from this address. The 32-bit table element is loaded into R0 from the table.
ARM in Thumb mode
The code is mostly the same, but less dense, because theLSLsuffix cannot be specified in theLDRinstruction here:
get_month1 PROC
LSLS r0,r0,#2
LDR r1,|L0.64|
LDR r0,[r1,r0]
BX lr
ENDP
18.5.3 ARM64
Listing 18.13: Optimizing GCC 4.9 ARM64
get_month1:
adrp x1, .LANCHOR0
add x1, x1, :lo12:.LANCHOR0
ldr x0, [x1,w0,sxtw 3]
ret
.LANCHOR0 =. + 0
.type month1, %object
.size month1, 96
month1:
.xword .LC2
.xword .LC3
.xword .LC4
.xword .LC5
.xword .LC6
.xword .LC7
.xword .LC8
.xword .LC9
.xword .LC10
.xword .LC11
.xword .LC12
.xword .LC13
.LC2:
.string "January"
.LC3:
.string "February"
.LC4:
.string "March"
.LC5:
.string "April"
.LC6:
.string "May"
.LC7:
.string "June"
.LC8:
.string "July"
.LC9:
.string "August"
.LC10:
.string "September"
.LC11:
.string "October"
.LC12: