Assembly Language for Beginners

(Jeff_L) #1

1.18. REPLACING ARITHMETIC INSTRUCTIONS TO OTHER ONES


Listing 1.193: Optimizing Keil 6/2013 (ARM mode)

; a7
||f1|| PROC
RSB r0,r0,r0,LSL #3
; R0=R0<<3-R0=R0
8-R0=a8-a=a7
BX lr
ENDP


; a28
||f2|| PROC
RSB r0,r0,r0,LSL #3
; R0=R0<<3-R0=R0
8-R0=a8-a=a7
LSL r0,r0,#2
; R0=R0<<2=R04=a74=a28
BX lr
ENDP


; a17
||f3|| PROC
ADD r0,r0,r0,LSL #4
; R0=R0+R0<<4=R0+R0
16=R017=a17
BX lr
ENDP


But there are no such modifiers in Thumb mode. It also can’t optimizef2():


Listing 1.194: Optimizing Keil 6/2013 (Thumb mode)

; a7
||f1|| PROC
LSLS r1,r0,#3
; R1=R0<<3=a<<3=a
8
SUBS r0,r1,r0
; R0=R1-R0=a8-a=a7
BX lr
ENDP


; a28
||f2|| PROC
MOVS r1,#0x1c ; 28
; R1=28
MULS r0,r1,r0
; R0=R1
R0=28*a
BX lr
ENDP


; a17
||f3|| PROC
LSLS r1,r0,#4
; R1=R0<<4=R0
16=a16
ADDS r0,r0,r1
; R0=R0+R1=a+a
16=a*17
BX lr
ENDP


MIPS


Listing 1.195: Optimizing GCC 4.4.5 (IDA)

_f1:
sll $v0, $a0, 3
; $v0 = $a0<<3 = $a08
jr $ra
subu $v0, $a0 ; branch delay slot
; $v0 = $v0-$a0 = $a0
8-$a0 = $a0*7


_f2:
sll $v0, $a0, 5

Free download pdf