Write a function called performDivision in ARM assembly lang
Write a function called performDivision in ARM assembly language that performs integer division, that is, it takes two arguments: a dividend from r0 and a divisor from r1 and return the integer quotient and remainder stored in r0 and r1. Use activation record to write the performDivision function.
Solution
The ARM code is as follows: Intially R0 and R1 are used as Dividend and divisor respectively. Then after division operation R0 stores the quotient and R1 stores the remainder.
********************************************************************************************
PERFORMDIVISION         PUSH    {R2}        ;store R2 Value
                                           MOVS    R2,#0       ;move 0 to R2 for quotient
                                           CMP     R1,#0       ;Compare divisor to 0
                                           BEQ     SETCARRY    ;if divisor = 0 go to SETCARRY
 WHILE                              CMP     R0,R1       ;Compare R0 to R1
                                           BLT     ENDWHILE    ;if dividend<Divisor End loop
                                           ADDS    R2,R2,#1    ;Add 1 to quotient
                                           SUBS    R0,R0,R1    ;Dividend - divisor
                                            B       WHILE       ;branch to start of while
 ENDWHILE   
                                     MOVS    R0,R2       ;move quotient to R0 and remainder is R1
                                      POP     {R2}        ;revert R2 to value before subroutine
                                      PUSH    {R0,R1}     ;push R0 and R1
                                      MRS     R0,APSR     ; Set C flag to 0
                                     MOVS    R1,#0x20    ; \"\"
                                      BICS    R0,R0,R1    ; \"\"
                                      MSR     APSR,R0     ; \"\"
                                      POP     {R0,R1}     ;revert R0 and R1 to answer
 QUITDIV                      BX      LR          ;Go back to program
 SETCARRY   
                                      PUSH    {R0,R1}     ;Store R0 and R1
                                      MRS     R0,APSR     ; Set C flag to 1
                                       MOVS    R1,#0x20    ;\"\"
                                       ORRS    R0,R0,R1    ;\"\"
                                       MSR     APSR,R0     ;\"\"
                                       POP     {R0,R1}     ;Revert R0 and R1 to answer
                                       B       QUITDIV     ;Go back to program

