Chapter 6 more commands
In this chapter, we will explore more arm commands, especially add, sub, And, Orr, EOR, and BIC. These commands are very similar and contain a displacement command, for example:
Add r0, R1, R2, LSR #2 @ R0 = R1 + (R2 logic shifts right 2)
Bic R9, R7, R3, Ror #16 @ R9 = R7 &~ (R3 loop shifts right 16)
You can simply do this without having to shift:
EOR R3, R3, R3 @ clear R3 (EOR is exclusive or, exclusive or)
These commands (in fact most arm commands) are in the following format:
Instruction DEST, operand2, operand3 [, shifter OP # number or register]
The entire operation is defined by instruction and executed on operand2 and operand3. The result is shifted and assigned to DeST. After these operations, only DEST is changed.
You may not be familiar with these commands, so let's take a look:
Add/sub-add (addition) and subtract (subtraction ). There is also a command RSB, which exchanges the subtrahend and subtrahend:
Normal: Sub r0, R1, R2 @ R0 = R1-R2.
Exchange: RSB r0, R1, R2 @ R0 = R2-R1.
And-bit domain and operation.
Bic-this is a concise instruction, a bit like and, but the bit set in the second operand will clear the corresponding bit in the first operand. In C, we use &~ (One operation and one inverse operation ). In fact, Bic indicates Bic clear (bit clearing ).
Orr-bit domain or operation
If you add S (such as ands, subs, adds,...) after these commands, the status mark will be affected. If you forget to add s in a loop, like the program in Chapter 2, and then execute the conditional jump statement, what you get is an endless loop.
Command CMP
You have seen this command before, but I still need to explain it in depth. This command compares two parameters and then sets the status flag based on the result so that you can perform some conditional operations. For example:
CMP R1, R0 @ compares R1 and R0. This is a very important command. Note that you can use displacement, for example:
CMP r0, #160 @ we have seen a similar one. What about this:
CMP R1, R0, LSL #2 @ compare R1 and (R0 logic shifts left 2 ). Remember that CMP never changes any register because it does not have the Dest part.
Any command can contain conditional code.
In fact, in the arm instruction set, all instructions can be added with conditional code, that is, the Code mentioned in the branch instruction can be as follows:
Orrlt R1, R3, R9 @ if the status flag shows lt, run R1 = R3 or R9. If the conditions are not met, this command is skipped.
All commands are applicable, with no exceptions. Is it useful?