How to do an assemble-time modulus on constants in ARM assembly language

后端 未结 3 1130
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 16:16

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         


        
相关标签:
3条回答
  • 2020-12-18 16:30

    Keil/armasm spells it :MOD:. See the manual http://www.keil.com/support/man/docs/armasm/armasm_Cacechjd.htm

    0 讨论(0)
  • 2020-12-18 16:45

    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.

    0 讨论(0)
  • 2020-12-18 16:46

    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.

    0 讨论(0)
提交回复
热议问题