Arithmetic and logic operations
The basic format of logical and integer arithmetic instructions is:
The parts of the instruction are as follows:
- Operation. This defines what the instruction does. For example,
ADDdoes addition and
ANDperforms a logical AND.
Scan be added to the operation to set flags. For example,
stells the processor to update the
ALUflags based on the result of instruction. We discuss
ALUflags in the section on generating condition code.
- Destination: The destination of the instruction is always a register, and specifies where the result of the operation is placed. Most instructions have a single destination register. A few instructions have two destination registers. When the destination is a
Wregister, the upper 32 bits of the corresponding
Xregister are set to 0.
- Operand 1: This will always be a register. This is the first input to the instruction.
- Operand 2: This will be a register or a constant, and is the second input to the instruction.
When operand 2 is a register, it may include an optional shift.
When operand 2 is a constant, it is encoded within the instruction itself. This means that the range of constants available is limited.
You should be aware of a couple of special cases, such as the
MOV moves a constant, or the contents of another register, into the register specified as the destination.
MVN only require a single input operand, which can be either a register or a constant, as shown here:
MOV X0, #1
X0 = 1
MVN W0, W1
W0 = ~W1