SUB[S] : Subtraction
SUB will subtract one value from another.
If the S bit is set (SUBS), the N and Z flags are set according to the result, and the C and V flags are set as follows: C if the result generated a borrow (a not carry; unsigned underflow); V if the result generated a signed overflow.
SUB is useful for basic subtraction. Use SBC to perform subtraction with the Carry flag considered.
SUBS can be a useful loop counter without the need for a comparison operation. Code such as the following may be used:
MOV R10, #123 ; our loop counter start value .loop ...some code here... SUBS R10, R10, #1 BNE loop ; comes to here when EQ (ie when R10 = 0)
SUB<suffix> <dest>, <op 1>, <op 2>
dest = op_1 - op_2
SUB R0, R0, R1 ; Subtract R1 from R0 SUB R0, R0, #1 ; Decrement R0 by one
The instruction bit pattern is as follows:
|31 - 28||27||26||25||24 - 21||20||19 - 16||15 - 12||11 - 0|
|condition||0||0||I||0 0 1 0||S||op_1||dest||op_2/shift|