SlideShare a Scribd company logo
Embedded Systems
MODULE 2
Assembly Basics
• we introduce some basic syntax of ARM assembly to
make it easier to understand the rest of the code
Assembler Language: Basic Syntax
ARM assembly syntax:
Label:
opcode operand1, operand2, ... ; Comments
• Label is used as a reference to an address location
• Opcode/Mnemonic is the name of the instruction;
• Operand1 is the destination of the operation;
• Operand2 is normally the source of the operation;
• Comments are written after” ; “ , which does not affect the program;
EXAMPLE:
Moving immediate data:
MOV R3, #0x11 ; Set register R3 to 0x11
Constants using EQU:
NVIC_IRQ_SETEN0 EQU 0xE000E100;
Use of DCI, DCB, DCD:
• DCI (Define Constant Instruction) can be used to code an instruction if the assembler
cannot generate the exact instruction
DCI 0xBE00 ; → Opcode for Breakpoint (BKPT 0) ,a 16 bit instruction
• DCB (Define Constant Byte) for defining byte size constant values, such as characters;
MY_NUMBER DCD 0x12345678; →MY_NUMBER =0x12345678 , Get the value
code
• DCD (Define Constant Data) for defining word size constant values to define binary
data in your code.
HELLO_TXT DCB "Hellon",0; →HELLO_TXT= Hello Various other instructions will
be explained later on
Assembler Language: Use of Suffixes
Table 4.1 Suffixes in Instructions
Suffix Description
S Update Application Program Status register (APSR)
(flags); for example: ADDS R0, R1 ; this will update APSR
EQ, NE, LT, GT, and Conditional execution; EQ = Equal, NE = Not Equal, LT=
Less Than, GT = Greater so on Than, and so forth. For example:
BEQ<Label> ; Branch if equal
Assembler Language: Unified Assembler Language
To support and get the best out of the Thumb®-2 instruction set, the Unified Assembler
Language (UAL) was developed to allow selection of 16-bit and 32-bit instructions and to
make it easier to port applications between ARM code and Thumb code by using the same
syntax for both.
ADD R0, R1 ; R0 = R0 + R1, using Traditional Thumb syntax
ADD R0, R0, R1 ; Equivalent instruction using UAL syntax
AND R0, R1 ; Traditional Thumb syntax
ANDS R0, R0, R1 ; Equivalent UAL syntax (S suffix is added)
ADDS R0, #1 ; Use 16-bit Thumb instruction by default
; for smaller size
ADDS.N R0, #1 ; Use 16-bit Thumb instruction (N=Narrow)
ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction (W=wide)
Instruction List
The ARM Cortex instruction can be classified into the following:
1. Moving Data
2. Pseudo-Instructions
3.Data processing instructions
4. Call & Unconditional Branch Instructions
5. Decision & Conditional Branch Instructions
6. Combined Compare & Conditional branch Instructions
7. Instruction Barrier & Memory Barrier Instructions
8. Saturation operation Instructions
9. Useful Thumb-2 instruction
Move instructions
This can be grouped into the following category:
• Moving Data Between Register And Register
• Moving An Immediate Data Value Into A Register
• Moving Data Between Memory And Register
• Moving Data Between Special Register And Register
(a) Moving Data Between Register And Register
MOV R8, R3;
data from R3 goes into R8.
(b) Moving An Immediate data value Into a Register
MOV R0,#0X12
12Hex goes into R0.
MOV R1, # ‘A’
ASCII value of A goes into R1.
MOVS R0, #0X78
Suffix S is used to move 8 bit or less than that into register 78H goes to
R0.
MOVW.W R0,#0X789A
it’s a thumb-2 instruction. Moves 32 bit data 0000789A to R0.
Data 3456789A can be stored in R0 as
MOVW.W R0,#0X789A
moves 789A as LOWER 16-bit data in R0.
MOVT.W R0,#0X3456
moves 3456 as HIGHER 16-bit data in R0.
MOVT
upper 16bits , MOVW
lower 16bits
(c) Moving Data Between Memory And Register
The ARM supports memory access via two instructions, LDR and STR
LDRB Rd, [Rn, #offset] Read byte from memory location Rn + offset
(Calculates an address from a base register value & an offset regiter value, Loads a byte
from memory,zero extends it to form a 32 bit word & writes it to a register)
LDRH Rd, [Rn, #offset] Read half word from memory location Rn + offset
LDR Rd, [Rn, #offset] Read word from memory location Rn + offset
LDRD Rd1,Rd2, [Rn, #offset] Read double word from memory location Rn + offset
(Calculate an address fron a base register value & an immediate offset, loads two words
from memory & writes them to two registers.)
STRB Rd, [Rn, #offset] Store byte to memory location Rn + offset
STRH Rd, [Rn, #offset] Store half word to memory location Rn + offset
STR Rd, [Rn, #offset] Store word to memory location Rn + offset
STRD Rd1,Rd2, [Rn, #offset] Store double word to memory location Rn + offset
The exclamation mark (!) in the instruction specifies whether the register Rd should be updated
after the instruction is completed.
“!” indicates the update of base register R1
STMIA.W R8!, {R0-R3} ; R8 changed to 0x8010 after store; (increment by 4 words)
STMIA.W R8 , {R0-R3} ; R8 unchanged after store.
(Store multiple,Increment after):-Stores multiple registers to consecutive memory locations
using an address from a base register)
ARM processors also support memory accesses with preindexing and postindexing.
(a) Pre-Indexing
• Pre-indexing load instructions for various sizes (word, byte, half word, and double word)
LDR.W Rd, [Rn, #offset]!
LDRB.W Rd, [Rn, #offset]!
LDRH.W Rd, [Rn, #offset]!
LDRD.W Rd1, Rd2,[Rn, #offset]!
• Pre-indexing load instructions for various sizes with sign extend (byte, half word)
LDRSB.W Rd, [Rn, #offset]!
LDRSH.W Rd, [Rn, #offset]!
Pre-indexing store instructions for various sizes (word, byte, half word, and double word)
STR.W Rd, [Rn, #offset]!
STRB.W Rd, [Rn, #offset]!
STRH.W Rd, [Rn, #offset]!
STRD.W Rd1, Rd2,[Rn, #offset]!
ARM Cortex-3 also supports multiple memory load and store operation with Increment after
and decrement before facility. This is illustrated below.
b) Post indexing
Postindexing memory access instructions carry out the memory transfer using the base address
specified by the register and then update the address register afterward.
For example,
LDR.W R0,[R1], #offset ; Read memory[R1], with R1 is updated to R1+offset
• Postindexing load instructions for various sizes (word, byte, half word, and double word)
LDR.W Rd, [Rn], #offset
LDRB.W Rd, [Rn], #offset
LDRH.W Rd, [Rn], #offset
LDRD.W Rd1, Rd2,[Rn], #offset
• Postindexing load instructions for various sizes with sign extend (byte, half word)
LDRSB.W Rd, [Rn], #offset
LDRSH.W Rd, [Rn], #offset
• Postindexing store instructions for various sizes (word, byte,half word, and double word)
STR.W Rd, [Rn], #offset
STRB.W Rd, [Rn], #offset
STRH.W Rd, [Rn], #offset
STRD.W Rd1, Rd2,[Rn], #offset
Two other types of memory operation are Stack PUSH and Stack POP.
Accessing Stack memory Locations through PUSH & POP
PUSH {R0, R4-R7, R9} ; Push R0, R4, R5, R6, R7, R9 into stack memory
POP {R2,R3} ; Pop R2 and R3 from stack
Usually, a PUSH instruction will have a corresponding POP with the same register list, but this is
not always necessary.
• For example, a common exception is when POP is used as a function return:
PUSH {R0-R3, LR} ; Save register contents at beginning of subroutine
.... ..........................; Processing
.......
........
POP {R0-R3, PC} ; restore registers and return
(d)Moving data between special Registers to another Register
To access APSR registers, one can use the instructions MRS and MSR. For example,
MRS R0, PSR ; Read Processor status word into R0
MSR CONTROL, R1 ; Write value of R1 into control register
• APSR can be written only in privileged mode.
Pseudo-Instructions
• Both LDR and ADR pseudo-instructions can be used to set registers to a program address
value. They have different syntaxes and behaviors.
• For LDR, if the address is a program address value, the assembler will automatically set
the LSB to 1.
LDR R0, = address1 ; R0 set to 0x4001
.............................
address1 ; address here is 0x4000
Mov R0, R1 ; address1 contains program code
• If address1 is a data address, LSB will not be changed.
LDR R0, =address1 ; R0 set to 0x4000
...
address1 ; address here is 0x4000
DCD 0x0 ; address1 contains data
• For ADR, one can load the address value of a program code into a register without setting
the LSB automatically and no equal sign (=) in the ADR statement is required.
ADR R0, address1
...
address1 ; (address here is 0x4000)
MOV R0, R1 ; address1 contains program code.
Data Processing Instructions
The Cortex-M3 provides many different instructions for data processing
(a) Arithmetic operation instructions include ADD, SUB, MUL, DIV, unsigned and signed
divide (UDIV/SDIV).
(b) Logical instructions include AND, OR, NOT, Exor, Shift & Rotate.
• ADD instruction can operate between two registers or between one register and an
immediate data value:
ADD R0, R0, R1 ; R0 = R0 + R1
ADDS R0, R0, #0x12 ; R0 = R0 + 0x12
ADD.W R0, R1, R2 ; R0 = R1 + R2
ADD.W R0, R1, R2 ; Flag unchanged. ADDS.W R0, R1, R2 ; Flag change.
All the Cortex-M3 Arithmetic Instructions are listed below:
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptx

More Related Content

Similar to Module 2 PPT of ES.pptx

S emb t4-arch_cpu
S emb t4-arch_cpuS emb t4-arch_cpu
S emb t4-arch_cpu
João Moreira
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
Dr. Pankaj Zope
 
Microprocessors and microcontrollers
Microprocessors and microcontrollers Microprocessors and microcontrollers
Microprocessors and microcontrollers
durga_sekar
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
Karthik Vivek
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
Nithin Santhosh
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
Nithin Santhosh
 
Instruction set summary
Instruction set summary Instruction set summary
Instruction set summary
janicetiong
 
swrp141.pdf
swrp141.pdfswrp141.pdf
swrp141.pdf
Watchsoft
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
Karthik Vivek
 
arm.pptx
arm.pptxarm.pptx
Lecture9
Lecture9Lecture9
Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
Arm (2)
Arm (2)Arm (2)
Arm (2)
jrosita
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
Ravi Babu
 
Instruction set.pptx
Instruction set.pptxInstruction set.pptx
Instruction set.pptx
ssuser000e54
 
addressing-mode-of-8051.pdf
addressing-mode-of-8051.pdfaddressing-mode-of-8051.pdf
addressing-mode-of-8051.pdf
DhilibanSwaminathan
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
commiebstrd
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction Set
Dwight Sabio
 
432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf
ShreeKrishnaTarai
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
RLJIT
 

Similar to Module 2 PPT of ES.pptx (20)

S emb t4-arch_cpu
S emb t4-arch_cpuS emb t4-arch_cpu
S emb t4-arch_cpu
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
Microprocessors and microcontrollers
Microprocessors and microcontrollers Microprocessors and microcontrollers
Microprocessors and microcontrollers
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Instruction set summary
Instruction set summary Instruction set summary
Instruction set summary
 
swrp141.pdf
swrp141.pdfswrp141.pdf
swrp141.pdf
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
arm.pptx
arm.pptxarm.pptx
arm.pptx
 
Lecture9
Lecture9Lecture9
Lecture9
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Arm (2)
Arm (2)Arm (2)
Arm (2)
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
Instruction set.pptx
Instruction set.pptxInstruction set.pptx
Instruction set.pptx
 
addressing-mode-of-8051.pdf
addressing-mode-of-8051.pdfaddressing-mode-of-8051.pdf
addressing-mode-of-8051.pdf
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction Set
 
432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf432_17EC563_8051-microcontroller-moving-data_notes.pdf
432_17EC563_8051-microcontroller-moving-data_notes.pdf
 
15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
 

Recently uploaded

Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 

Recently uploaded (20)

Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 

Module 2 PPT of ES.pptx

  • 2. Assembly Basics • we introduce some basic syntax of ARM assembly to make it easier to understand the rest of the code Assembler Language: Basic Syntax ARM assembly syntax: Label: opcode operand1, operand2, ... ; Comments • Label is used as a reference to an address location • Opcode/Mnemonic is the name of the instruction; • Operand1 is the destination of the operation; • Operand2 is normally the source of the operation; • Comments are written after” ; “ , which does not affect the program; EXAMPLE:
  • 3. Moving immediate data: MOV R3, #0x11 ; Set register R3 to 0x11 Constants using EQU: NVIC_IRQ_SETEN0 EQU 0xE000E100; Use of DCI, DCB, DCD: • DCI (Define Constant Instruction) can be used to code an instruction if the assembler cannot generate the exact instruction DCI 0xBE00 ; → Opcode for Breakpoint (BKPT 0) ,a 16 bit instruction • DCB (Define Constant Byte) for defining byte size constant values, such as characters; MY_NUMBER DCD 0x12345678; →MY_NUMBER =0x12345678 , Get the value code • DCD (Define Constant Data) for defining word size constant values to define binary data in your code. HELLO_TXT DCB "Hellon",0; →HELLO_TXT= Hello Various other instructions will be explained later on
  • 4. Assembler Language: Use of Suffixes Table 4.1 Suffixes in Instructions Suffix Description S Update Application Program Status register (APSR) (flags); for example: ADDS R0, R1 ; this will update APSR EQ, NE, LT, GT, and Conditional execution; EQ = Equal, NE = Not Equal, LT= Less Than, GT = Greater so on Than, and so forth. For example: BEQ<Label> ; Branch if equal
  • 5. Assembler Language: Unified Assembler Language To support and get the best out of the Thumb®-2 instruction set, the Unified Assembler Language (UAL) was developed to allow selection of 16-bit and 32-bit instructions and to make it easier to port applications between ARM code and Thumb code by using the same syntax for both. ADD R0, R1 ; R0 = R0 + R1, using Traditional Thumb syntax ADD R0, R0, R1 ; Equivalent instruction using UAL syntax AND R0, R1 ; Traditional Thumb syntax ANDS R0, R0, R1 ; Equivalent UAL syntax (S suffix is added) ADDS R0, #1 ; Use 16-bit Thumb instruction by default ; for smaller size ADDS.N R0, #1 ; Use 16-bit Thumb instruction (N=Narrow) ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction (W=wide)
  • 6. Instruction List The ARM Cortex instruction can be classified into the following: 1. Moving Data 2. Pseudo-Instructions 3.Data processing instructions 4. Call & Unconditional Branch Instructions 5. Decision & Conditional Branch Instructions 6. Combined Compare & Conditional branch Instructions 7. Instruction Barrier & Memory Barrier Instructions 8. Saturation operation Instructions 9. Useful Thumb-2 instruction
  • 7. Move instructions This can be grouped into the following category: • Moving Data Between Register And Register • Moving An Immediate Data Value Into A Register • Moving Data Between Memory And Register • Moving Data Between Special Register And Register
  • 8. (a) Moving Data Between Register And Register MOV R8, R3; data from R3 goes into R8. (b) Moving An Immediate data value Into a Register MOV R0,#0X12 12Hex goes into R0. MOV R1, # ‘A’ ASCII value of A goes into R1. MOVS R0, #0X78 Suffix S is used to move 8 bit or less than that into register 78H goes to R0. MOVW.W R0,#0X789A it’s a thumb-2 instruction. Moves 32 bit data 0000789A to R0. Data 3456789A can be stored in R0 as MOVW.W R0,#0X789A moves 789A as LOWER 16-bit data in R0. MOVT.W R0,#0X3456 moves 3456 as HIGHER 16-bit data in R0. MOVT upper 16bits , MOVW lower 16bits
  • 9. (c) Moving Data Between Memory And Register The ARM supports memory access via two instructions, LDR and STR LDRB Rd, [Rn, #offset] Read byte from memory location Rn + offset (Calculates an address from a base register value & an offset regiter value, Loads a byte from memory,zero extends it to form a 32 bit word & writes it to a register) LDRH Rd, [Rn, #offset] Read half word from memory location Rn + offset LDR Rd, [Rn, #offset] Read word from memory location Rn + offset LDRD Rd1,Rd2, [Rn, #offset] Read double word from memory location Rn + offset (Calculate an address fron a base register value & an immediate offset, loads two words from memory & writes them to two registers.) STRB Rd, [Rn, #offset] Store byte to memory location Rn + offset STRH Rd, [Rn, #offset] Store half word to memory location Rn + offset STR Rd, [Rn, #offset] Store word to memory location Rn + offset STRD Rd1,Rd2, [Rn, #offset] Store double word to memory location Rn + offset
  • 10. The exclamation mark (!) in the instruction specifies whether the register Rd should be updated after the instruction is completed. “!” indicates the update of base register R1 STMIA.W R8!, {R0-R3} ; R8 changed to 0x8010 after store; (increment by 4 words) STMIA.W R8 , {R0-R3} ; R8 unchanged after store. (Store multiple,Increment after):-Stores multiple registers to consecutive memory locations using an address from a base register) ARM processors also support memory accesses with preindexing and postindexing. (a) Pre-Indexing • Pre-indexing load instructions for various sizes (word, byte, half word, and double word) LDR.W Rd, [Rn, #offset]! LDRB.W Rd, [Rn, #offset]! LDRH.W Rd, [Rn, #offset]! LDRD.W Rd1, Rd2,[Rn, #offset]! • Pre-indexing load instructions for various sizes with sign extend (byte, half word) LDRSB.W Rd, [Rn, #offset]! LDRSH.W Rd, [Rn, #offset]!
  • 11. Pre-indexing store instructions for various sizes (word, byte, half word, and double word) STR.W Rd, [Rn, #offset]! STRB.W Rd, [Rn, #offset]! STRH.W Rd, [Rn, #offset]! STRD.W Rd1, Rd2,[Rn, #offset]! ARM Cortex-3 also supports multiple memory load and store operation with Increment after and decrement before facility. This is illustrated below.
  • 12. b) Post indexing Postindexing memory access instructions carry out the memory transfer using the base address specified by the register and then update the address register afterward. For example, LDR.W R0,[R1], #offset ; Read memory[R1], with R1 is updated to R1+offset • Postindexing load instructions for various sizes (word, byte, half word, and double word) LDR.W Rd, [Rn], #offset LDRB.W Rd, [Rn], #offset LDRH.W Rd, [Rn], #offset LDRD.W Rd1, Rd2,[Rn], #offset • Postindexing load instructions for various sizes with sign extend (byte, half word) LDRSB.W Rd, [Rn], #offset LDRSH.W Rd, [Rn], #offset • Postindexing store instructions for various sizes (word, byte,half word, and double word) STR.W Rd, [Rn], #offset STRB.W Rd, [Rn], #offset STRH.W Rd, [Rn], #offset STRD.W Rd1, Rd2,[Rn], #offset
  • 13. Two other types of memory operation are Stack PUSH and Stack POP. Accessing Stack memory Locations through PUSH & POP PUSH {R0, R4-R7, R9} ; Push R0, R4, R5, R6, R7, R9 into stack memory POP {R2,R3} ; Pop R2 and R3 from stack Usually, a PUSH instruction will have a corresponding POP with the same register list, but this is not always necessary. • For example, a common exception is when POP is used as a function return: PUSH {R0-R3, LR} ; Save register contents at beginning of subroutine .... ..........................; Processing ....... ........ POP {R0-R3, PC} ; restore registers and return
  • 14. (d)Moving data between special Registers to another Register To access APSR registers, one can use the instructions MRS and MSR. For example, MRS R0, PSR ; Read Processor status word into R0 MSR CONTROL, R1 ; Write value of R1 into control register • APSR can be written only in privileged mode.
  • 15. Pseudo-Instructions • Both LDR and ADR pseudo-instructions can be used to set registers to a program address value. They have different syntaxes and behaviors. • For LDR, if the address is a program address value, the assembler will automatically set the LSB to 1. LDR R0, = address1 ; R0 set to 0x4001 ............................. address1 ; address here is 0x4000 Mov R0, R1 ; address1 contains program code • If address1 is a data address, LSB will not be changed. LDR R0, =address1 ; R0 set to 0x4000 ... address1 ; address here is 0x4000 DCD 0x0 ; address1 contains data • For ADR, one can load the address value of a program code into a register without setting the LSB automatically and no equal sign (=) in the ADR statement is required. ADR R0, address1 ... address1 ; (address here is 0x4000) MOV R0, R1 ; address1 contains program code.
  • 16. Data Processing Instructions The Cortex-M3 provides many different instructions for data processing (a) Arithmetic operation instructions include ADD, SUB, MUL, DIV, unsigned and signed divide (UDIV/SDIV). (b) Logical instructions include AND, OR, NOT, Exor, Shift & Rotate. • ADD instruction can operate between two registers or between one register and an immediate data value: ADD R0, R0, R1 ; R0 = R0 + R1 ADDS R0, R0, #0x12 ; R0 = R0 + 0x12 ADD.W R0, R1, R2 ; R0 = R1 + R2 ADD.W R0, R1, R2 ; Flag unchanged. ADDS.W R0, R1, R2 ; Flag change. All the Cortex-M3 Arithmetic Instructions are listed below: