Lecture-08 ARM - Data Processing Instructions
Lecture-08 ARM - Data Processing Instructions
Microcontroller
Lecture-8A: ARM Assembly Language Programming
by
Dr. Ramesh Chinthala
Amrita Vishwa Vidyapeetham, Bengaluru
ARM – Assembly Language
Programming
• The ARM processor is very easy to program at the assembly level,
• though for most applications it is more appropriate to program in a high-level language such as C or
C++
• 8085 instruction opcode is 8-bit long and it can support 246 different binary instruction types
• ARM instruction is 32-bit long, and it can support ______________ different binary instruction types
• The assembler converts the assembly language instruction to machine language instruction, you don’t
need to remember all
• But, need to know a instruction formats
• We will see ARM assembly language programming at user level
• We will learn how to write simple ARM programs
• ARM emulator runs programming
• ARM development board runs programming
ARM – Assembly Language
Programming
• The ARM processor is very easy to program at the assembly level,
• though for most applications it is more appropriate to program in a high-level language such as C or
C++
• 8085 instruction opcode is 8-bit long and it can support 246 different binary instruction types
• ARM instruction is 32-bit long, and it can support ______232______ different binary instruction types
• The assembler converts the assembly language instruction to machine language instruction, you don’t
need to remember all
• But, need to know a instruction formats
• We will see ARM assembly language programming at user level
• We will learn how to write simple ARM programs
• ARM emulator runs programming
• ARM development board runs programming
ARM – Assembly Language
Programming
• Data processing instructions
• Data Transfer instructions
• Control Flow instructions
ARM – Assembly Language
Programming
• Data processing instructions
• Data Transfer instructions
• Control Flow instructions
ARM – Data processing instructions
• Below are rules for which apply to ARM data processing instructions
• All operands are 32-bit wide and come from registers or are specified
as literals (constant) in instruction itself
• ADD R1, R2, R3; valid instruction?
• ADD R1, R2, #04; valid instruction?
• The result is 32-bit wide and is placed in a register
• MUL R2, R1, R0; is result 32-bit wide?
• Each of the operand registers and the result register are
independently specified in the register
ARM – Data processing instructions
• Below are rules for which apply to ARM data processing instructions
• All operands are 32-bit wide and come from registers or are specified
as literals (constant) in instruction itself
• ADD R1, R2, R3; valid instruction? yes
• ADD R1, R2, #04; valid instruction?
• The result is 32-bit wide and is placed in a register
• MUL R2, R1, R0; is result 32-bit wide?
• Each of the operand registers and the result register are
independently specified in the register
ARM – Data processing instructions
• Below are rules for which apply to ARM data processing instructions
• All operands are 32-bit wide and come from registers or are specified
as literals (constant) in instruction itself
• ADD R1, R2, R3; valid instruction? yes
• ADD R1, R2, #04; valid instruction? Yes, 2nd operand is immediate val
• The result is 32-bit wide and is placed in a register
• MUL R2, R1, R0; is result 32-bit wide?
• Each of the operand registers and the result register are
independently specified in the register
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Arithmetic operations
• ADD R0, R1, R2; R0 := R1 + R2
• ADC R0, R1, R2; R0 := R1 + R2 + ?
• SUB R0, R1, R2; R0 := R1 - R2
• SBC R0, R1, R2; R0 := R1 - R2 + ?
• RSB R0, R1, R2; R0 := R2 – R1
• RSC R0, R1, R2; R0 := R2 – R1 + ?
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Arithmetic operations
• ADD R0, R1, R2; R0 := R1 + R2
• ADC R0, R1, R2; R0 := R1 + R2 + Carry Flag value
• SUB R0, R1, R2; R0 := R1 - R2
• SBC R0, R1, R2; R0 := R1 - R2 + ?
• RSB R0, R1, R2; R0 := R2 – R1
• RSC R0, R1, R2; R0 := R2 – R1 + ?
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Arithmetic operations
• ADD R0, R1, R2; R0 := R1 + R2
• ADC R0, R1, R2; R0 := R1 + R2 + Carry Flag value
• SUB R0, R1, R2; R0 := R1 - R2
• SBC R0, R1, R2; R0 := R1 - R2 + ( (C-1) or Cbar )
• RSB R0, R1, R2; R0 := R2 – R1
• RSC R0, R1, R2; R0 := R2 – R1 + ?
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Arithmetic operations
• ADD R0, R1, R2; R0 := R1 + R2
• ADC R0, R1, R2; R0 := R1 + R2 + Carry Flag value
• SUB R0, R1, R2; R0 := R1 - R2
• SBC R0, R1, R2; R0 := R1 - R2 + ( (C-1) or Cbar )
• RSB R0, R1, R2; R0 := R2 – R1
• RSC R0, R1, R2; R0 := R2 – R1 + ( (C-1) or Cbar )
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Bit-wise logical operations
• AND R0, R1, R2; R0 := R1 and R2
• ORR R0, R1, R2; R0 := R1 or R2
• EOR R0, R1, R2; R0 := R1 xor R2
• BIC R0, R1, R2; R0 := R1 and (not R2)
• In BIC – bit clear instruction every one in the second operand clear
the corresponding bit in the first operand
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Register movement operations
• MOV R0, R2; R0 := R2
• MNV R0, R2; R0 := not R2, 1’s complement of R2 into R0
ARM – Data processing instructions
• Operands Types: Simple Operand registers
• Comparison operations
• CMP R1, R2; set cc on R1- R2
• CMN R1, R2; set cc on R1 + R2
• TST R1, R2; set cc on R1 and R2
• TEQ R1, R2; sett cc on R1 xor R2
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01, #01 means decimal value
• ADC R8, R7, #&FF; R8 = R7 + ?,
• Can we use a 32-bit immediate value?
• Valid Immediate = ?
•?
•?
•?
•?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01, #01 means decimal value
• ADC R8, R7, #&FF; R8 = R7 + ?, #&FF means hexa-decimal value
• Can we use a 32-bit immediate value?
• Valid Immediate = ?
•?
•?
•?
•?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01, #01 means decimal value
• ADC R8, R7, #&FF; R8 = R7 + 255, #&FF means hexa-decimal value
• Can we use a 32-bit immediate value?
• Valid Immediate = ?
•?
•?
•?
•?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = ?
•?
• ?
•?
• ?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = (0-255)x22n, where n = 0 to 12
• 0000-0001-0000-0001 not a valid,
• ?
• 0000-0001-0000-0010
• ?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = (0-255)x22n
• 0000-0001-0000-0001 not a valid,
• ?
• 0000-0001-0000-0010 a valid,
• ?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = (0-255)x22n
• 0000-0001-0000-0001 not a valid, because LSB-bit-1 to MSB-bit-1, 9-bits
• ?
• 0000-0001-0000-0010 a valid, because LSB-bit-1 to MSB-bit-1, 8-bits,
• ?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = (0-255)x22n
• 0000-0001-0000-0001 not a valid, because LSB-bit-1 to MSB-bit-1, 9-bits
• where LSB-bit-0 is not taken care by left shift
• 0000-0001-0000-0010 a valid, because LSB-bit-1 to MSB-bit-1, 8-bits,
• ?
ARM – Data processing instructions
• Operands Types: Immediate Operands
• ADD R3, R3, #01; R3 := R3 + 01
• ADC R8, R7, #&FF; R8 = R7 + ?
• Can we use a 32-bit immediate value:No, only 8-bit or shifted value of 8-
bit
• Valid Immediate = (0-255)x22n
• 0000-0001-0000-0001 not a valid, because LSB-bit-1 to MSB-bit-1, 9-bits
• where LSB-bit-0 is not taken care by left shift
• 0000-0001-0000-0011 not valid, because LSB-bit-1 to MSB-bit-1, 9-bits,
• where LSB-bit-0 is taken care by left shift
Valid Immediate values
• Y = 0000-0001-0000-0010 is valid, bcoz 9-bit is shifted version of some 8-bit pattern
• X = 0000-0000-1000-0001
• Y = 0000-0001-0000-0010 = left shift X by 1-bit, where X is a 8-bit pattern (only)