Data Processing
Adding S to the end of any of the mnemonics causes the status register (officially referred to as
the Current Processor Status Register CPSR) to be updated according to the result from the
Arithmetic & Logic Unit (ALU). The bits set in the status register are used as the “cc” code to
determine if data operations are to be executed and in conditional branch instructions to deter-
mine if a branch is taken. The four bits in the status register that are used to determine conditions
are: the zero bit Z (the result of the arithmetic operation was all zeros), the sign bit N (N=’1’
means the ALU result is negative, N=’0’ indicates a positive or zero result), the carry bit C (C=1
indicates the carry bit out of the most significant ALU bit is ‘1’, C=’0’ means the carry bit out
of the most significant ALU bit is ‘0’), and an overflow bit V (V=’1’ means that two positive
quantities have added to yield a negative result, or two negative quantities have added to give a
positive result. V=’0’ indicates the operation performed is in range).
There are 15 general purpose registers, R0 to R14, that you can use in your code; R15 contains
the Program Counter and should not be manipulated by you! The CPSR is another, separate
register held within the microprocessor.
AppendixB.29
TEQcc Rn, Rm/#nn ;set status on Rn XOR Rm/#nn
If the second source operand is a register (Rm), it can be shifted (see later).
In data processing instructions, the literal value, #nn, is restricted. Bits set to 1 need to span a
maximum of eight bits anywhere within the 32 bits. Thus 0x11C (=228) is ok as a literal as is
0x002E4000 but 0x103 is invalid. In test.s, loading 0x103 into register R1 is performed by two
instructions (move followed by add). An alternative is to do a LDR instruction (see Assembler
Supplied ‘Pseudo Operations’ later).
Shifting
If the data processing operation specifies the second operand as a register (Rm) then this can be
optionally shifted by a shift amount specified as a literal #c or by the amount specified in the
borrom eight bits of a register Rc. The shift on Rm is performed prior to combining it with the
first source operand Rn, and the contents of register Rm are unaffected by the shift operation.
You will notice that there is no arithmetic shift left; this is because it is equivalent to a logical
shift left. Shifting is useful in scaling variables. For example, multiplying by two yields a far
better performance if the variable is logically shifted left one place. Similarly scaling a number
by dividing by two can be achieved by an arithmetic shift right of one place. The shifts are:
AppendixB.30
RRX ;one place right shift. Carry from
;status reg shifts into most signif-
;icant bit and if status reg set by
;instruction, least signicant bit
;updates carry bit in status regis-
;ter. This enables a 1-bit circular
;rotate through the carry
The shift required on Rm is specified as the fourth parameter in the instruction e.g.
add r1, r4, r5, LSL #3
This results in r1 being set to r4+8*r5
Control Transfer
AppendixB.31
Special Control Operations
NOP ; no operation
MOV Rd, #-nn ; assembles to MVN
CMP Rn, #-nn ; assembles to CMN
Directives
AppendixB.32
DEFS &<number e.g. 20> ;Reserves 20 bytes
;at this point
Condition Codes
EQ Equal Z
NE Not Equal Z
MI Minus (negative) N
PL Plus (positive) N
VS Overflow Set V
VC Overflow Clear V
AL Always TRUE
Operators in Expressions
It is possible, and often valuable, to allow the assembler to work out some values (such as the
length of strings and tables). Thus instead of a simple number, an integer expression can be
used. The following is a summary of the most useful ones.
Unary operators:
+, -, ~
AppendixB.33
Numbers
AppendixB.34