Data processing instructions help the computer do math and move information inside it. They are simple commands that tell the processor to add, subtract, copy, or compare numbers.
Data processing instructions (ADD, SUB, MOV, CMP) in ARM Architecture
ADD Rd, Rn, Operand2 SUB Rd, Rn, Operand2 MOV Rd, Operand2 CMP Rn, Operand2
Rd is the destination register where the result is stored.
Rn is the first source register.
Operand2 can be a register or an immediate value (a number).
ADD R1, R2, R3
SUB R4, R4, #5MOV R0, #10CMP R5, R6
This program moves 20 into R0 and 10 into R1. Then it adds R0 and R1, storing 30 in R2. It subtracts R1 from R0, storing 10 in R3. Finally, it compares R2 and R3 to see which is bigger.
MOV R0, #20 MOV R1, #10 ADD R2, R0, R1 SUB R3, R0, R1 CMP R2, R3
The CMP instruction does not save a result but sets special flags used to make decisions later.
Immediate values start with a # sign, like #5 or #10.
Registers are like small boxes inside the processor that hold numbers temporarily.
ADD and SUB do math by adding or subtracting numbers in registers.
MOV copies a number or value into a register.
CMP compares two numbers and sets flags for decision-making.
Practice
ADD instruction do in ARM architecture?Solution
Step 1: Understand the purpose of ADD
The ADD instruction performs addition of two values stored in registers.Step 2: Identify the result storage
The result of the addition is stored back into a register.Final Answer:
Adds values from two registers and stores the result in a register -> Option DQuick Check:
ADD means addition operation [OK]
- Confusing ADD with MOV which copies values
- Thinking ADD compares values like CMP
- Assuming ADD subtracts values
Solution
Step 1: Identify the instruction for copying values
MOV is used to copy a value into a register.Step 2: Check the syntax for immediate value
The immediate value 5 is written as #5, so MOV R1, #5 copies 5 into R1.Final Answer:
MOV R1, #5 -> Option BQuick Check:
MOV copies value to register [OK]
- Using ADD or SUB instead of MOV to copy values
- Forgetting # before immediate values
- Using CMP which only compares values
MOV R0, #10
SUB R0, R0, #3What is the value in register R0 after execution?
Solution
Step 1: Execute MOV instruction
MOV R0, #10 sets register R0 to 10.Step 2: Execute SUB instruction
SUB R0, R0, #3 subtracts 3 from R0 (10 - 3 = 7) and stores result in R0.Final Answer:
7 -> Option AQuick Check:
10 minus 3 equals 7 [OK]
- Adding instead of subtracting
- Not updating R0 after SUB
- Confusing immediate and register operands
MOV R2, #8
CMP R2, #8
ADD R3, R2Solution
Step 1: Check MOV and CMP instructions
MOV R2, #8 and CMP R2, #8 are correct syntax for moving and comparing immediate values.Step 2: Analyze ADD instruction
ADD requires three operands: destination, first source, second source. Here, ADD R3, R2 misses the third operand.Final Answer:
ADD instruction missing second operand -> Option CQuick Check:
ADD needs 3 operands [OK]
- Assuming CMP syntax is wrong
- Thinking MOV can't use immediate values
- Ignoring missing operand in ADD
Solution
Step 1: Compare R4 with 15
CMP R4, #15 sets flags based on comparison.Step 2: Use BEQ to branch if equal
BEQ label_true jumps to label_true if R4 equals 15.Step 3: Move 0 if not equal, else move 1
If not equal, MOV R5, #0 executes; branch skips to label_end. At label_true, MOV R5, #1 sets R5 to 1.Final Answer:
Sequence in option A correctly implements the logic -> Option AQuick Check:
CMP + BEQ + conditional MOV sequence [OK]
- Moving values before comparison
- Not branching correctly on equality
- Incorrect order of instructions
Ready to prove it?
Pass the test and this pattern moves unknown
