I want to know how to do modulus in arm assembly language
I've tried the code in this page MOD operator in arm website:
MOV R1,#12 MOD 7 ; R1 = 5
MOV R2,#99 MOD 10 ; R2 = 9
but it doesn't assemble.
I'm using the keil assembler.
I want to know how to do modulus in arm assembly language
I've tried the code in this page MOD operator in arm website:
MOV R1,#12 MOD 7 ; R1 = 5
MOV R2,#99 MOD 10 ; R2 = 9
but it doesn't assemble.
I'm using the keil assembler.
If you're looking for runtime modulo instead of assemble-time, you can do div and mod using two instructions:
;Precondition: R0 % R1 is the required computation
;Postcondition: R0 has the result of R0 % R1
: R2 has R0 / R1
; Example comments for 10 % 7
UDIV R2, R0, R1 ; 1 <- 10 / 7 ; R2 <- R0 / R1
MLS R0, R1, R2, R0 ; 3 <- 10 - (7 * 1) ; R0 <- R0 - (R1 * R2 )
Documentation for MLS, which was designed exactly for this use-case.
Keil/armasm spells it :MOD:
. See the manual http://www.keil.com/support/man/docs/armasm/armasm_Cacechjd.htm
If you're using the GNU assembler (you don't say), then the mod (remainder) operator is %
, same as C.
The fine manual is here.