--------------------------------------------------------- N |Negative result from ALU flag --------------------------------------------------------- Z |Zero result from ALU flag --------------------------------------------------------- C |ALU operation Carried out --------------------------------------------------------- V |ALU operation oVerflowed ---------------------------------------------------------
-------------------------------------------------------- EQ |Z set (equal) -------------------------------------------------------- NE |Z clear (not equal) -------------------------------------------------------- CS/HS |C set (unsigned >=) -------------------------------------------------------- CC/LO |C clear (unsigned <) -------------------------------------------------------- MI |N set (negative) -------------------------------------------------------- PL |N clear (positive or zero) -------------------------------------------------------- VS |V set (overflow) -------------------------------------------------------- VC |V clear (no overflow) -------------------------------------------------------- HI |C set and Z clear (unsigned >) -------------------------------------------------------- LS |C clear and Z set (unsigned <=) -------------------------------------------------------- GE |N and V the same (signed >=) -------------------------------------------------------- LT |N and V differ (signed <) -------------------------------------------------------- GT |Z clear, N and V the same (signed >) -------------------------------------------------------- LE |Z set, N and V differ (signed <=) -------------------------------------------------------- AL |Always execute (the default if none is |specified) --------------------------------------------------------
Without conditional execution this could be naively coded as:
while (a != b)
{ if (a > b) a -= b;
else b -= a;
}
Conditional execution and selective setting of the PSR'S ALU flags allows
it to be coded much more compactly as follows (this version can be found
in the examples directory as gcd.s).
gcd CMP a1, a2
BEQ end
BLT lessthan
SUB a1, a1, a2
B gcd
lessthan
SUB a2, a2, a1
B gcd
end
Two tricks are illustrated:
gcd CMP a1, a2
SUBGT a1, a1, a2
SUBLT a2, a2, a1
BNE gcd
Compile, link and run the C version of the gcd routine by using the following commands:
where somewhere is the directory in which armlib.32l can be
found.
armcc -c gcd.c -li -apcs 3/32bit
armcc -c gcdtest.c -li -apcs 3/32bit
armlink -o gcdtest gcd.o gcdtest.o somewhere/armlib.321
armsd -li gcdtest
The armlink command links your relocatable objects with the ARM C library to create a runnable program (here called gcdtest).
The armsd command invokes the debugger, with gcdtest as the program to be run. Again -li specifies that little-endian memory is required (as with armasm above).
You can assemble, link and run the assembler gcd routine by using the following commands:
where somewhere is the directory in which armlib.32l can be
found.
armasm gcd.s -o gcd.o -li
armcc -c gcdtest.c -li -3/32bit
armlink -o gcdtest gcd.o gcdtest.o somewhere/armlib.32l
armsd -li gcdtest
The armcc command compiles the test harness. The -c flag tells armcc not to link its output with the C library; the -li flag tells armcc to compile for a little-endian memory (as with armasm).
The armlink command links your relocatable objects with the ARM C library to create a runnable program (here called gcdtest).
The armsd command invokes the debugger, with gcdtest as the program to be run. Again -li specifies that little-endian memory is required (as with armasm above).