Microprocessor Design and the ARM

Arithmetic Operations

Example: ADD r0, r1, r2 ; r0 := r1 + r2

r1 and r2 are the source registers containing the input operands, r0 is the destination register where the result is stored. The destination register can be the same as one of the source registers, i.e. ADD r0, r0, r1 is legal and means add the values in r0 and r1 together and place the result in r0.

This ADD instruction can be used on both unsigned and 2's complement signed numbers. It may produce a carry out signal and set overflow bits, but such signals are ignored by default.

ADD r0, r1, r2 ; r0 := r1 + r2
ADC r0, r1, r2 ; r0 := r1 + r2 + C
SUB r0, r1, r2 ; r0 := r1 - r2
SBC r0, r1, r2 ; r0 := r1 - r2 + C - 1
RSB r0, r1, r2 ; r0 := r2 - r1
RSC r0, r1, r2 ; r0 := r2 - r1 + C - 1

The ADC, SBC, and RSC instructions utilise the value of the carry bit (C) whose value is stored in the Current Program Status Register (covered in the next lecture). Thus the ADC instruction example, ADC r0, r1, r2, adds the values stored in r1 and r2 and the value of the carry bit, placing the result in r0. In the SBC instruction, the carry bit is used to indicate a "borrow", which is unset (set to 0) when a "borrow" is required. These instructions are useful in that they allow programmers to perform arithmetic operations on numbers that are larger than 32 bits.

RSB is shorthand for "reverse subtraction" (and RSC is "reverse subtraction with carry") and switches the order of operands for the subtraction process.