![Samsung S3C2501X User Manual Download Page 188](http://html.mh-extra.com/html/samsung/s3c2501x/s3c2501x_user-manual_340828188.webp)
S3C2501X
INSTRUCTION SET
3-97
3.39 INSTRUCTION SET EXAMPLES
The following examples show ways in which the THUMB instructions may be used to generate small and efficient
code. Each example also shows the ARM equivalent so these may be compared.
3.39.1 MULTIPLICATION BY A CONSTANT USING SHIFTS AND ADDS
The following shows code to multiply by various constants using 1, 2 or 3 Thumb instructions alongside the ARM
equivalents. For other constants it is generally better to use the built-in MUL instruction rather than using a
sequence of 4 or more instructions.
Thumb
ARM
1. Multiplication by 2^n (1,2,4,8,...)
LSL
Ra, Rb, LSL #n
; MOV Ra, Rb, LSL #n
2. Multiplication by 2^n+1 (3,5,9,17,...)
LSL
Rt, Rb, #n
; ADD Ra, Rb, Rb, LSL #n
ADD
Ra, Rt, Rb
3. Multiplication by 2^n-1 (3,7,15,...)
LSL
Rt, Rb, #n
; RSB Ra, Rb, Rb, LSL #n
SUB
Ra, Rt, Rb
4. Multiplication by -2^n (-2, -4, -8, ...)
LSL
Ra, Rb, #n
; MOV Ra, Rb, LSL #n
MVN
Ra, Ra
; RSB Ra, Ra, #0
5. Multiplication by -2^n-1 (-3, -7, -15, ...)
LSL
Rt, Rb, #n
; SUB Ra, Rb, Rb, LSL #n
SUB
Ra, Rb, Rt
Multiplication by any C = {2^n+1, 2^n-1, -2^n or -2^n-1} * 2^n
Effectively this is any of the multiplications in 2 to 5 followed by a final shift. This allows the following additional
constants to be multiplied. 6, 10, 12, 14, 18, 20, 24, 28, 30, 34, 36, 40, 48, 56, 60, 62 .....
(2..5)
; (2..5)
LSL
Ra, Ra, #n
; MOV Ra, Ra, LSL #n
Summary of Contents for S3C2501X
Page 18: ......
Page 275: ...MEMORY CONTROLLER S3C2501X 5 60 NOTES ...
Page 289: ...I2C CONTROLLER S3C2501X 6 14 NOTES ...
Page 373: ...GDMA CONTROLLER S3C2501X 9 24 NOTES ...
Page 435: ...I O PORTS S3C2501X 12 12 NOTES ...