The add instruction

  • The add instruction of ARM can:

    1. add the (32 bits) value in a register and a small constant

    2. add the (32 bits) value in 2 register

    The sum is always stored in a register


  • Syntax and meaning of the add instruction of ARM:

     add  rdest, rsrc1, #n    // rdest = rsrc1 + n
     add  rdest, rsrc1, rsrc2  // rdest = rsrc1 + rsrc2
    

    Examples:

      add  r0, r0, #1      // r0 = r0 + 1
      add  r0, r1, r2      // r0 = r1 + r2
      add  r0, r0, r0      // r0 = r0 + r0 = 2Śr0
    

DEMO: demo/asm/2+add/add.s

The sub (subtract) instruction

  • The sub instruction of ARM can:

    1. subtract the (32 bits) value in a register and a small constant

    2. subtract the (32 bits) value in 2 register

    The difference is always stored in a register


  • Syntax and meaning of the sub instruction of ARM:

     sub  rdest, rsrc1, #n    // rdest = rsrc1 - n
     sub  rdest, rsrc1, rsrc2  // rdest = rsrc1 - rsrc2
    

    Examples:

      sub  r0, r0, #1      // r0 = r0 - 1
      sub  r0, r1, r2      // r0 = r1 - r2
    

DEMO: demo/asm/2+add/sub.s

The rsb (reverse subtract) instruction

  • The rsb instruction of ARM can:

    1. reverse subtract the (32 bits) value in a register and a small constant

    2. reverse subtract the (32 bits) value in 2 register

    The difference is always stored in a register


  • Syntax and meaning of the rsb instruction of ARM:

     rsb  rdest, rsrc1, #n    // rdest = n - rsrc1
     rsb  rdest, rsrc1, rsrc2  // rdest = rsrc2 - rsrc1
    

    rsb is only used as follows:

      rsb  r1, r0, #0      // r1 = 0 - r0 = -r0
                           // Same as: neg r1, r0
    

DEMO: demo/asm/2+add/rsb.s

The mul (multiply) instruction

  • The mul instruction of ARM can:

    1. only multiply the (32 bits) value in 2 register

    The product is always stored in a register


  • Syntax and meaning of the mul instruction of ARM:

     mul  rdest, rsrc1, rsrc2  // rdest = rsrc1 × rsrc2
                             // Note: rdest and rsrc1 must be different 
    

    Examples:

      mul  r2, r0, r1      // r2 = r0 * r1
      mul  r0, r0, r1      // Error !  
    

DEMO: demo/asm/2+add/mul.s

Divide

  • ARM does not have a divide instruction !

  • Reason:

    • Division is rarely used in computer programs

    • It would be a waste of chip space to to make a division circuit for an operation that is seldom used....


  • How does ARM support division:

    • With a library function...

    Note:

    • We will not use divide in CS255