02 - Data Processing Instructions
02 - Data Processing Instructions
02 - Data Processing Instructions
CMPE 364
Microprocessor Based Design
SPRING 2021
4
Data Processing Instructions Summary
Register movement operations:
MOV, MVN
Arithmetic operations Covered in this
ADD, ADDC, SUB, SUBC, RSB, RSC set of slides
Bit-wise logical operations
AND, EOR, ORR, BIC
Multiplication instructions
MUL, UMUL, SMUL, MLA, UMLAL, SMLAL
Comparison operations
TST, TEQ, CMP, CMN
5
Register Transfer Instructions
MOV and MVN
6
MOV Instruction
Copies N (the source) into a destination register Rd, where N is a
register or immediate value.
Useful for setting initial values and transferring data between
registers
PRE r5=5
r7=8
MOV r7, r5 ; let r7 = r5
POST r5=5
r7=5
MOV Instruction
Operand N is either a register Rm or a constant preceded by #.
Example
given the instruction shown below, get r3 and r9 after execution.
Assume r3 = 0xFEEA082C and r9 = 0x8000AC40?
MOV r3, r9
Solution
r3 = 0x8000AC40 and r9 remains the same.
MOV Instruction
Example
Determine r1 after execution on next instruction assuming it contains
0x2E059401?
Solution
r1 = 0x0000009C
MOV Instruction
Example
Determine r10 after execution on next instruction assuming it contains
0x2E059401?
Solution
Hex of 384 = 256 + 128
r10 = 0x00000180
MVN Instruction
Move Negative Instruction.
Has same effect of MOV instruction but copies the one’s
complement of the source to destination.
Source: general purpose register or immediate
Solution:
r2 = 0x31FF57DB, r5 = SAME.
MVN Instruction
Example: Determine the content of r4 after the execution of the
following instruction?
MVN r4, #24
Solution:
BEFORE: #24 = 0000 0000 0000 0000 0000 0000 0001 10002
#24 = 0x00000018.
AFTER: r4 = 1111 1111 1111 1111 1111 1111 1110 01112
r4 = 0xFFFFFFE7.
Arithmetic Instructions
ADD, ADDC, SUB, SUBC, RSB, RSC
15
Arithmetic Instructions
The arithmetic instructions implement addition and subtraction
of 32-bit signed and unsigned values.
N is the result of the shifter operation. The syntax of shifter operation will be shown later.
ADD Instruction
ADD instruction adds 2 source operands SRC1 and SRC2, and
stores the result in destination register DST.
The first source operand must be general purpose register, while
the other can be a register or an immediate operand.
Answer:
r9 = 0x0033A021
r0 and r3 No Change
ADD Examples
Example:
Get r1 and r6 after the next instruction, if
r6 = 0xFFFFFFFE (-2?)
Answer:
r1 = 0x00000016 = 22.
SUB Instruction
The SUB instruction subtracts the 2nd source (SRC2) from the 1st
source (SRC1) and replaces the result in destination register (DST).
SUB DST, SRC1, SRC2
EXAMPLE: Get r4 if
r2 = 0x000006A0
r1 = 0x000003C4
SOLUTION: r4 = 0x000002DC
SUB Instruction
SOLUTION:
r4 = 0x000008E0 – 0xFFFFFFFE = 0x000008E2
RSB Instruction
RSB is Reverse Subtract Instruction.
Subtracts SRC1 from SRC2
SOLUTION: r8 = r9 – r3 = 0x000002EE
RSB Instruction
EXAMPLE:
Write Assembly instruction to subtract r7 from 1000 and replace
result in r7?
SOLUTION:
RSB r7, r7, #1000
EXAMPLE
Write a single code to convert the sign of r1 register without
knowing its content?
SOLUTION:
RSB r1, r1, #0
ADC Instruction: Add with Carry
Add with Carry bit
ADC DST, SRC1, SRC2
Adds the SRC1 with SRC2 with Carry bit in CPSR register and
places result in DST.
SRC1 should be a register, while SRC2 can be a register or a
immediate operand.
ADC Instruction: Add with Carry
EXAMPLE: Get r6 after the execute of next instruction if
r11 = 0x000E5FA9
r10 = 0x00005204
CF = 1
SOLUTION:
r11 = r10 + r11 + C = 0x000EB1AE
ADC Instruction: Add with Carry
EXAMPLE: Get r4 after the execution of next instruction, if
r2 = 0x80040608 and CPSR = 0x50000010?
SOLUTION:
r4 = r2 + 134 + 0 = 0x8004068E
Multiword Arithmetic Example
Write instructions to add a 64-bit integer contained in r2 and r3
to another 64-bit integer contained in r0 and r1, and place the
result in r4 and r5.
Solution:
ADDS r4, r0, r2 ; adding the least significant words
ADC r5, r1, r3 ; adding the most significant words
carry
r1 r0
+
r3 r2
r5 r4
27
SBC Instruction
SBC is subtract with carry.
Subtracts the SRC2 and complement of carry bit in CPSR
register from SRC1 and places the result in DST
DST = SRC1 – SRC2 – Not(C)
SBC DST, SRC1, SRC2
r5 r4
29
RSC Instruction
RSC: Reverse Subtract with Carry
Subtracts SRC1 And complement of Carry from SRC2
and places the result in DST register.
DST = SRC2 – SRC1 – Not C
RSC DST, SRC1, SRC2
RSC Example
EXAMPLE: Get r3, if CPSR = 0x0000010,
r0 = 0x08009420,
r2 = 0x014520C0,
SOLUTION:
r3 = r0 – r2 – 1 = 08009420 – 014520C0 – 1 = 0x06BB735F
31
Bitwise Logical Instructions
AND, EOR, ORR, BIC
32
Logical Instructions
Logical instructions perform bitwise logical operations on the
two source registers.
Allow individual bit manipulation: at bit level
SOLUTION:
mask = 0000 0000 0000 1011 0000 0000 0000 0000
= 0x000B0000
SOLUTION:
Will use an ORR instruction, ORing r1 register with a 32-bit Mask.
Mask will be = 0x --------?
ORR r0, r0, #0x00000280
EOR (Exclusive OR) Instruction
Exclusive OR which performs Exclusive OR of 2 sources, SRC1
And SRC2, and places result in DST.
42