ARM 教材 - cortex-m - 5 - 算數 - Arithmetic
Index: Data Processing
Hackpad
加減(反向減)乘除
ADC: Add with carry
e.g. ADC R2, R1, R0 ; R2 = R1 + R0 + C
SBC : sub with carry
e.g. SBC R0, R1, R2 ; R0 = R1- R2 +C -1
RSB: reverse subtraction
RSC: reverse subtraction with carry
Hackpad
加減(反向減)乘除
算數運算 : ADD / ADC / SUB / SBC / RSB
加: ADD
e.g. ADD R2, R1, R0 ; R2=R1+R0
e.g. ADD R2, R0, #2 ; R2=R1+2
e.g. ADD R2, R0 ; R2 += R0
e.g. ADD R8, R7, #&FF ; r8 = r7 & 0x000000FF
e.g. ADD R8, R7, #&FF ; r8 = r7 & 0x000000FF
ADC: Add with carry
e.g. ADC R2, R1, R0 ; R2 = R1 + R0 + C
--------------------
減: SUB
e.g. SUB R0, R1, #6 ; R0=R1-6
e.g. RSB R0, R1, #6 ; R0=6-R1
SBC : sub with carry
e.g. SBC R0, R1, R2 ; R0 = R1- R2 +C -1
RSB: reverse subtraction
RSC: reverse subtraction with carry
- RSB r0, r1, r2 ; r0 := r2 - r1
- RSC r0, r1, r2 ; r0 := r2 - r1 + C - 1
--------------------
乘: MUL
R4 = 0x00000077 (119)
R3 = 0xFFFFFF10 (-240)
MUL R5, R4, R3
R5 = 0xFFFF9070 (-28560)
overflow:
R6=0x0000BEAD (48813)
R7=0x000157B5 (87989)
MUL R8, R6, R7
R8 = 0x00009B51 (39761) => 4295007057 (0x100009B51)
MLS : multiply with subtract
MLS R4,R5,R6,R7 ; R4 = R7-(R5*R6)
--------------------
除: UDIV (unsigned) SDIV (signed)
R2=0x4
R0=0x2
UDIV R3, R2, R0
R3=0x2
R1=0x3
R2=0x4
UDIV R4, R2, R1
R4=0x1
UDIV R5, R1, R2
R5=0x0
R6 = 0xFFFFFF00 (4294967040) (-256)
R7 = 0x5
UDIV R8, R6, R7
SDIV R9, R6, R7
R8 = 0x33333300 (858993408)
R9 = 0xFFFFFFCD (-51)
除法餘數 (%) 如何 implement
- r0 ; time ;
- ARM function call 參數並不是都推到 stack. 前幾個會直接帶在 r0-r3 來加速
- time % 60 => 搭配除法乘法得到餘數, 沒有單一指令
- r2 = time / 60;
- ret = time - (60*r2)
MLS r0, r1, r2, r0 ; r0 = r0 - (r1*r2)
留言
張貼留言