Beruflich Dokumente
Kultur Dokumente
NSYSU CSE
Chap. 3
Each of the operand registers and the result registers are independently specified in the instruction
ARM uses a 3-address format for these instructions In writing the assembly language source code, the operands must be
written in the correct order, which is result register first, then the first operand and lastly the second operand.
NSYSU CSE
Chap. 3
Reverse subtract
C flag is set to
each bit pair of the input operands AND: r0[i] := r1[i] AND r2[i] for each value of i from 0 to 31 BIC: bit clear where every 1 in the second operand clears the corresponding bit in the first
NSYSU CSE
Chap. 3
assembly language format, and simply move the second operand to the destination
Comparison operations
These instructions do not produce a result but just set the condition
code bits (N, Z, C and V) in the CPSR according to the selected operation
compare compare negated test test equal
NSYSU CSE Chap. 3
The second example shows that the immediate value may be specified in hexadecimal (base 16) notation by putting & after the # Most valid immediate values are given by immediate = (0255) 22n, where 0 n 12
the assembler will also replace MOV with MVN, ADD with SUB, and
LSR
logical shift right by 0 to 31 places; fill the vacated bits at the most
ASL
arithmetic shift left (is a synonym for LSL)
ASR
arithmetic shift right by 0 to 32 places; fill the vacated bits at the most
significant end of the word with zeros if the source operand was positive, or with ones if the source operand was negative
NSYSU CSE Chap. 3
RRX
rotate right extended by 1 place; the vacated bit (bit 31) is filled with
the old value of the C flag and the operand is shifted one place to the right
It is also possible to use a register value to specify the number of bits the second operand should be shifted by: ADD r5, r5, r3, LSL, r2 ; r5 := r5 + r3 2r2
NSYSU CSE
Chap. 3
31
31
00000
00000
LSL #5
31 0 0 31 1
LSR #5
0
00000 0
1 1 11 1 1 , positive operand 0 C
ASR #5
31
ASR #5
31
, negative operand 0
ROR #5
RRX
0 operand 2
destination register first operand register set condition codes arithmetic/logic function 25 1 immediate alignment 11 7 6 5 4 3 0 #shift Sh 0 Rm 11 #rot 8 7 8-bit immediate 0
25 0
10
r2-r3
11
Condition Flags
Logical Instruction Flag Negative (N=1) Zero (Z=1) Carry (C=1) oVerflow (V=1) No meaning
Arithmetic Instruction
Bit 31 of the result has been set Indicates a negative number in signed operations Result of operation was zero Result was greater than 32 bits Result was greater than 31 bits Indicates a possible corruption of the sign bit in signed numbers
Result is all zeroes After Shift operation 1 was left in carry flag No meaning
NSYSU CSE
Chap. 3
12
r4, r3, r2
There are some important differences from the other arithmetic instructions:
Immediate second operands are not supported The result register must not be the same as the first source register If the S bit is set the V flag is preserved (as for a logical instruction)
Multiplying two 32-bit integers gives a 64-bit result, the least significant 32 bits of which are placed in the result register and the rest are ignored
ARM also support long multiply instructions which place the most
NSYSU CSE
Chap. 3
13
Multiplication by a constant
can be implemented by loading the constant into a register and then
using one of these instructions, but it is usually more efficient to use a short series of data processing instructions using shifts and adds or subtracts
ADD RSB
; r0 := 5 r0 ; r0 := 7 r0 (= 35 r0)
NSYSU CSE
Chap. 3
14
value in memory, effectively doing both a load and a store operation in one instruction
NSYSU CSE
Chap. 3
15
Other forms of addressing all build on this form, adding immediate (base-plus-offset ) or register offsets (base-plus-index ) to the base address LDR r0, [ r1 , #4 ] ; r0 := mem32 [ r1 + 4 ]
16
NSYSU CSE
Chap. 3
NSYSU CSE
Chap. 3
17
NSYSU CSE
Chap. 3
18
NSYSU CSE
Chap. 3
19
On the ARM this auto-indexing costs no extra time since it is performed on the processors datapath while the data is being fetched from memory
NSYSU CSE
Chap. 3
20
For example
NSYSU CSE
Chap. 3
21
NSYSU CSE
Chap. 3
22
Since the transferred data items are always 32-bit words, the base address (r1) should be word-aligned The order of the registers within the list is insignificant and does not affect the order of transfer or the values in the registers after the instruction has executed
NSYSU CSE
Chap. 3
23
descending
NSYSU CSE
Chap. 3
24
r0 has increased by 32 since the ! causes it to auto-index across eight words FD postfix: Full Descending stack address mode IA postfix: Increment After
NSYSU CSE
Chap. 3
25
r9 r5 r1 r9 r0
1018
16
r9
r5 r1 r0
1018
16
100c
16
r9
xx xx xx xx
100c
16
xx xx xx
LDMDB LDMEA
1000
16
1000
16
LDMDA LDMFA
xx xx xx
r9 r5 r1 r0 r9
1018
16
xx xx xx
1018
16
100c
16
r9
xx
r5 r1
100c
16
1000
16
r9
r0
1000
16
26
Be f o re Increment Af t e r Be f o re De c re me n t Af t e r
As cendi ng Ful l Empt y STMIB STMFA STMIA STMEA LDMDB LDMEA LDMDA LDMFA
Des cendi ng Ful l Empt y LDMIB LDMED LDMIA LDMFD STMDB STMFD STMDA STMED
Table 3.1 The mapping between the stack and block copy views of the load and store multiple instructions
NSYSU CSE
Chap. 3
27
LABEL
Conditional branches
The mechanism used to control loop exit is conditional branching
NSYSU CSE
Chap. 3
28
B ra n c h B BAL BEQ BNE BPL BM I BCC BLO BCS BHS BVC BVS BGT BGE BLT BLE BHI BLS
I n t e rp re t a t i o n Un co n ditio n al Alway s Equal No t equal Plus M in us Carry clear Lo wer Carry s et Hig h er o r s ame Ov erflo w clear Ov erflo w s et Greater th an Greater o r equal Les s th an Les s o r equal Hig h er Lo wer o r s ame
N o rm a l us e s Alway s tak e th is b ran ch Alway s tak e th is b ran ch Co mp aris o n equal o r zero res ult Z=1 Co mp aris o n n o t equal o r n o n -zero res ult Z=0 Res ult p o s itiv e o r zero Res ult min us o r n eg ativ e Arith metic o p eratio n did n o t g iv e carry -o ut Un s ig n ed co mp aris o n g av e lo wer Arith metic o p eratio n g av e carry -o ut Un s ig n ed co mp aris o n g av e h ig h er o r s ame Sig n ed in teg er o p eratio n ; n o o v erflo w o ccurred Sig n ed in teg er o p eratio n ; o v erflo w o ccurred Sig n ed in teg er co mp aris o n g av e g reater th an Sig n ed in teg er co mp aris o n g av e g reater o r equal Sig n ed in teg er co mp aris o n g av e les s th an Sig n ed in teg er co mp aris o n g av e les s th an o r equal Un s ig n ed co mp aris o n g av e h ig h er Un s ig n ed co mp aris o n g av e lo wer o r s ame
29
NSYSU CSE
Chap. 3
30
NSYSU CSE
Chap. 3
31
The subroutine should not call a further, nested, subroutine without first saving r14, otherwise the new return address will overwrite the old one
NSYSU CSE Chap. 3
32
NSYSU CSE
Chap. 3
33
R14 is used as the subroutine link register (LR) and stores the return address when Branch with Link operations are performed, calculated from the PC. Thus to return from a linked branch
MOV r15,r14
or
MOV pc,lr
NSYSU CSE Chap. 3
34
The same stack model is used for both the store and the load, ensuring that the correct values will be collected
NSYSU CSE
Chap. 3
35
NSYSU CSE
Chap. 3
36
JUMPTAB
BL JUMPTAB .. CMP r0, #0 BEQ SUB0 CMP r0, #1 BEQ SUB1 CMP r0, #2 BEQ SUB2 ..
JUMPTAB
SUBTAB
JUMPTAB r1, SUBTAB r0, #SUBMAX pc, [r1, r0, LSL #2] ERROR SUB0 SUB1 SUB2
NSYSU CSE
Chap. 3
37
NSYSU CSE
Chap. 3
38