Assembly Language for Beginners

(Jeff_L) #1

1.20. ARRAYS


DCB "June",0
DCB "July",0
DCB "August",0
DCB "September",0
DCB "October",0
DCB "November",0
DCB "December",0

AREA ||.data||, DATA, ALIGN=2
month1
DCD ||.conststring||
DCD ||.conststring||+0x8
DCD ||.conststring||+0x11
DCD ||.conststring||+0x17
DCD ||.conststring||+0x1d
DCD ||.conststring||+0x21
DCD ||.conststring||+0x26
DCD ||.conststring||+0x2b
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.


Theninputvaluemonthisshiftedleftby2(whichisthesameasmultiplyingby4), thenaddedtoR1(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 theLDR
instruction here:


get_month1 PROC
LSLS r0,r0,#2
LDR r1,|L0.64|
LDR r0,[r1,r0]
BX lr
ENDP


ARM64


Listing 1.237: 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

Free download pdf