SlideShare a Scribd company logo
1 of 27
Download to read offline
TI-RSLK
Texas Instruments Robotics System Learning Kit
Texas Instruments
| ARM Cortex M - Architecture
Module 3
Lecture: ARM Cortex M - Architecture
Texas Instruments
| ARM Cortex M - Architecture
ARM Cortex M Architecture
2
You will learn in this module
 Cortex M Architecture
• Buses
• CISC versus RISC
• Registers
• Memory
• Addressing modes
Texas Instruments
| ARM Cortex M - Architecture
ARM Cortex M Architecture
3
ARM Cortex-M4 processor
 Harvard versus von Neumann architecture
 Different busses for instructions and data
• ICode bus - Fetch op codes from ROM
• System bus - Data from RAM and I/O
• Dcode bus - Debugging
• PPB bus - Private peripherals
𝐴 = 𝜋𝑟2
Texas Instruments
| ARM Cortex M - Architecture
Reduced Instruction Set Computer (RISC)
4
RISC machine
• Pipelining provides single cycle operation for many instructions
• Thumb-2 configuration employs both 16 and 32-bit instructions
CISC RISC
Many instructions Few instructions
Instructions have varying lengths Instructions have fixed lengths
Instructions execute in varying times Instructions execute in 1 or 2 bus cycles
Many instructions can
access memory
Few instructions can access memory
 Load from memory to a register
 Store from register to memory
In one instruction, the processor can both
• Read memory and
• Write memory
 No one instruction can both read and write
memory in the same instruction
Fewer and more specialized registers
• Some registers contain data
• Others contain addresses
 Many identical general purpose registers
Many different types of addressing modes
Limited number of addressing modes
 Register, PC - relative
 Immediate
 Indexed
Texas Instruments
| ARM Cortex M - Architecture
Registers
5
32 bits wide
Stack
Link
Program
Condition Code Bits Indicates
N negative Result is negative
Z zero Result is zero
V overflow Signed overflow
C carry Unsigned overflow
Where are data?
 Registers
 RAM
 ROM
 I/O ports
Where are commands?
 ROM (pointed to by PC)
Texas Instruments
| ARM Cortex M - Architecture
Memory Map
6
8 bits wide
For the detailed Memory Map go to http://www.ti.com/lit/ds/symlink/msp432p401r.pdf
Texas Instruments
| ARM Cortex M - Architecture
Endianness
7
16-bit 1000 = 0x03E8
32-bit 1000000 = 0x000F4240
ASCII string “Jon” = 0x4A,0x6F,0x6E,0x00
Texas Instruments
| ARM Cortex M - Architecture
Addressing Modes: immediate
8
MOV R0,#100
Register
Immediate
Indexed
PC-relative
Texas Instruments
| ARM Cortex M - Architecture
Addressing Modes: Indexed
9
LDR R0,[R1]
Register
Immediate
Indexed
PC-relative
Texas Instruments
| ARM Cortex M - Architecture
Addressing Modes: Indexed
10
LDR R0,[R1,#4]
Register
Immediate
Indexed
PC-relative
Texas Instruments
| ARM Cortex M - Architecture
Variable Access: Load/store architecture
11
Increment: .asmfunc
LDR R1,CountAddr ; R1=pointer to Count
LDR R0,[R1] ; R0=value of Count
ADD R0,R0,#1
STR R0,[R1]
BX LR
.endasmfunc
CountAddr .field Count,32
[PC,#8]
0x20000000
uint32_t Count;
void Increment(void){
Count++;
}
Register
Immediate
Indexed
PC-relative
Texas Instruments
| ARM Cortex M - Architecture
ARM Cortex M Architecture
12
Summary
 Architecture
• Buses
• Registers
• Memory
• Addressing modes
Terms:
• RISC vs CISC
• Little vs big endian
• Address vs data
• Variables
Register
Immediate
Indexed
PC-relative
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Module 3
Lecture: ARM Cortex M Assembly Programming
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
2
You will learn in this module
 Assembly Programming
• Logical and shift operations
• Addition, subtraction, multiplication and divide
• Accessing memory
• Stack
• Functions, parameters
• Conditionals
• Loops
ARM Cortex M Assembly Programming
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
3
A
Rn
B
Operand2
A&B
AND
A|B
ORR
A^B
EOR
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
ORR R0,R1,R2
R1 0001 0010 0011 0100 0101 0110 0111 1000
R2 1000 0111 0110 0101 0100 0011 0010 0001
ORR 1001 0111 0111 0101 0101 0111 0111 1001
<op2>
• Register
• Register, shifted
• Constant
AND {Rd,} Rn, <op2> ;Rd=Rn&op2
ORR {Rd,} Rn, <op2> ;Rd=Rn|op2
EOR {Rd,} Rn, <op2> ;Rd=Rn^op2
Logic Operations
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Shift Operations
4
LSR Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned)
LSR Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned)
ASR Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed)
ASR Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed)
LSL Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned)
LSL Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned)
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Arithmetic Operations
5
 Addition/subtraction
• Two n-bit → n+1 bits
 Multiplication
• Two n-bit → 2n bits
 Avoid overflow
• Restrict input values
• Promote to higher, perform,
check, demote
 Division
• Avoid divide by 0
• Watch for dropout
 Signed versus unsigned
• Either signed or unsigned, not both
• Be careful about converting types
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Addition and Subtraction
6
ADD {Rd,} Rn, <op2> ;Rd = Rn + op2
SUB {Rd,} Rn, <op2> ;Rd = Rn - op2
CMP Rn, <op2> ;Rn - op2
Sets the carry bit Condition
Code Bits Indicates
N negative Result is negative
Z zero Result is zero
V overflow Signed overflow
C carry Unsigned overflow
<op2>
• Register
• Register, shifted
• Constant
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Multiplication and Division
7
uint32_t N,M;
// times 0.6
void Fun(void){
M = 3*N/5;
}
.data
.align 2
N .space 4
M .space 4
.text
.align 2
Fun: .asmfunc
LDR R3, Naddr ; R3 = &N (R3 points to N)
LDR R1, [R3] ; R1 = N
MOV R0, #3 ; R0 = 3
MUL R1, R0, R1 ; R1 = 3*N
MOV R0, #5 ; R0 = 5
UDIV R0, R1, R0 ; R0 = 3*N/5
LDR R2, MAddr ; R2 = &M (R2 points to M)
STR R0, [R2] ; M = 3*N/5
BX LR
.endasmfunc
NAddr .field N,32
MAddr .field M,32
MUL {Rd,} Rn, Rm ;Rd = Rn * Rm
UDIV {Rd,} Rn, Rm ;Rd = Rn/Rm unsigned
SDIV {Rd,} Rn, Rm ;Rd = Rn/Rm signed
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Stack
8
PUSH {R0}
PUSH {R1}
PUSH {R2}
POP {R3}
POP {R4}
POP {R5}
Push
1. SP=SP-4
2. Store at SP
POP
1. Read at SP
2. SP=SP+4
Usage
• Temporary storage
• Local variables
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
// random.c
uint32_t static M;
void Seed(uint32_t x){
M = x;
}
uint8_t Rand(void){
M=1664525*M+1013904223;
return M>>24;
}
Function calls
9
.data
.align 2
M .space 4
.text
.align 2
Seed: .asmfunc
LDR R1,MAddr ; R1=&M
STR R0,[R1] ; set M
BX LR
.endasmfunc
Rand: .asmfunc
LDR R2,MAddr ; R2=&M, address of M
LDR R0,[R2] ; R0=M, value of M
LDR R1,Slope
MUL R0,R0,R1 ; R0 = 1664525*M
LDR R1,Offst
ADD R0,R0,R1 ; 1664525*M+1013904223
STR R0,[R2] ; store M
LSR R0,#24 ; 0 to 255
BX LR
.endasmfunc
MAddr .field M,32
Slope .field 1664525,32
Offst .field 1013904223,32
.data
.align 2
n .space 4
.text
.align 2
main: .asmfunc
MOV R0,#1
BL Seed
loop BL Rand
LDR R1,nAddr
STR R0,[R1]
B loop
.endasmfunc
nAddr .field n,32
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
Conditionals
10
LDR R3,G2Addr ; R3=&G2, address of G2
LDR R2,[R3] ; R2=G2, value of G2
LDR R0,G1Addr ; R0=&G1, address of G1
LDR R1,[R0] ; R1=G1, value of G1
CMP R1,R2 ; compare G1 G2
BHI isNo
isYes BL Yes ; G1<=G2
B done
isNo BL No
done
G1Addr .field G1,32
G2Addr .field G2,32
Instruction Branch if
B target ; always
BEQ target ; equal (signed or unsigned)
BNE target ; not equal (signed or unsigned)
BLO target ; unsigned less than
BLS target ; unsigned less than or equal to
BHS target ; unsigned greater than or equal to
BHI target ; unsigned greater than
BLT target ; signed less than
BGE target ; signed greater than or equal to
BGT target ; signed greater than
BLE target ; signed less than or equal to
if(G2<=G1){
Yes();
}else{
No();
}
Think of the three steps
1) bring first value into a register,
2) compare to second value,
3) conditional branch, bxx
(where xx is eq ne lo ls hi hs gt ge lt or le).
The branch will occur if (first is xx second).
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
While Loops
11
while(G2>G1){
Body();
}
LDR R3,G2Addr ; R3=&G2, address of G2
LDR R2,[R3] ; R2=G2, value of G2
LDR R0,G1Addr ; R0=&G1, address of G1
LDR R1,[R0] ; R1=G1, value of G1
loop CMP R1,R2 ; compare G1 G2
BLS done
BL Body ; G1>G2
B loop
done
G1Addr .field G1,32 ;unsigned 32-bit number
G2Addr .field G2,32 ;unsigned 32-bit number
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
For Loops
12
MOV R4,#10
loop BL Body
SUBS R4,R4,#1
BNE loop
MOV R4,#10
loop CMP R4,#0
BEQ done
BL Body
SUB R4,R4,#1
B loop
done
for(i=10; i!=0; i--){
Body(); // 10 times
}
Texas Instruments Robotics System Learning Kit: The Maze Edition
SWRP141
| ARM Cortex M - Assembly Programming
ARM Cortex M Assembly Programming
13
Summary
 Programming
• Accessing memory
• Logical and shift operations
• Addition, subtraction, multiplication and divide
• Stack
• Functions, parameters
• Conditionals
• Loops
Register
Immediate
Indexed
PC-relative
IMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCES
Texas Instruments Incorporated (‘TI”) technical, application or other design advice, services or information, including, but not limited to,
reference designs and materials relating to evaluation modules, (collectively, “TI Resources”) are intended to assist designers who are
developing applications that incorporate TI products; by downloading, accessing or using any particular TI Resource in any way, you
(individually or, if you are acting on behalf of a company, your company) agree to use it solely for this purpose and subject to the terms of
this Notice.
TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI
products, and no additional obligations or liabilities arise from TI providing such TI Resources. TI reserves the right to make corrections,
enhancements, improvements and other changes to its TI Resources.
You understand and agree that you remain responsible for using your independent analysis, evaluation and judgment in designing your
applications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications
(and of all TI products used in or for your applications) with all applicable regulations, laws and other applicable requirements. You
represent that, with respect to your applications, you have all the necessary expertise to create and implement safeguards that (1)
anticipate dangerous consequences of failures, (2) monitor failures and their consequences, and (3) lessen the likelihood of failures that
might cause harm and take appropriate actions. You agree that prior to using or distributing any applications that include TI products, you
will thoroughly test such applications and the functionality of such TI products as used in such applications. TI has not conducted any
testing other than that specifically described in the published documentation for a particular TI Resource.
You are authorized to use, copy and modify any individual TI Resource only in connection with the development of applications that include
the TI product(s) identified in such TI Resource. NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE TO
ANY OTHER TI INTELLECTUAL PROPERTY RIGHT, AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTY
RIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN, including but not limited to any patent right, copyright, mask work right, or
other intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
regarding or referencing third-party products or services does not constitute a license to use such products or services, or a warranty or
endorsement thereof. Use of TI Resources may require a license from a third party under the patents or other intellectual property of the
third party, or a license from TI under the patents or other intellectual property of TI.
TI RESOURCES ARE PROVIDED “AS IS” AND WITH ALL FAULTS. TI DISCLAIMS ALL OTHER WARRANTIES OR
REPRESENTATIONS, EXPRESS OR IMPLIED, REGARDING TI RESOURCES OR USE THEREOF, INCLUDING BUT NOT LIMITED TO
ACCURACY OR COMPLETENESS, TITLE, ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL
PROPERTY RIGHTS.
TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM, INCLUDING BUT NOT
LIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IF
DESCRIBED IN TI RESOURCES OR OTHERWISE. IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL,
COLLATERAL, INDIRECT, PUNITIVE, INCIDENTAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH OR
ARISING OUT OF TI RESOURCES OR USE THEREOF, AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
You agree to fully indemnify TI and its representatives against any damages, costs, losses, and/or liabilities arising out of your non-
compliance with the terms and provisions of this Notice.
This Notice applies to TI Resources. Additional terms apply to the use and purchase of certain types of materials, TI products and services.
These include; without limitation, TI’s standard terms for semiconductor products http://www.ti.com/sc/docs/stdterms.htm), evaluation
modules, and samples (http://www.ti.com/sc/docs/sampterms.htm).
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2018, Texas Instruments Incorporated

More Related Content

Similar to swrp141.pdf

Similar to swrp141.pdf (20)

Lecture9
Lecture9Lecture9
Lecture9
 
ARM.ppt
ARM.pptARM.ppt
ARM.ppt
 
The ARM Architecture: ARM : ARM Architecture
The ARM Architecture: ARM : ARM ArchitectureThe ARM Architecture: ARM : ARM Architecture
The ARM Architecture: ARM : ARM Architecture
 
Arm
ArmArm
Arm
 
Lec02
Lec02Lec02
Lec02
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
 
Unit 4 _ ARM Processors .pptx
Unit 4 _ ARM Processors .pptxUnit 4 _ ARM Processors .pptx
Unit 4 _ ARM Processors .pptx
 
Unit II Arm 7 Introduction
Unit II Arm 7 IntroductionUnit II Arm 7 Introduction
Unit II Arm 7 Introduction
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
ARM_2.ppt
ARM_2.pptARM_2.ppt
ARM_2.ppt
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
Arm architecture
Arm architectureArm architecture
Arm architecture
 
A0220105
A0220105A0220105
A0220105
 
80x86_2.pdf
80x86_2.pdf80x86_2.pdf
80x86_2.pdf
 
06. thumb instructions
06. thumb instructions06. thumb instructions
06. thumb instructions
 
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptxModule 2 PPT of ES.pptx
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
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
B instruction set
B instruction setB instruction set
B instruction set
 
Introduction to ARM
Introduction to ARMIntroduction to ARM
Introduction to ARM
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 

swrp141.pdf

  • 2. Texas Instruments | ARM Cortex M - Architecture Module 3 Lecture: ARM Cortex M - Architecture
  • 3. Texas Instruments | ARM Cortex M - Architecture ARM Cortex M Architecture 2 You will learn in this module  Cortex M Architecture • Buses • CISC versus RISC • Registers • Memory • Addressing modes
  • 4. Texas Instruments | ARM Cortex M - Architecture ARM Cortex M Architecture 3 ARM Cortex-M4 processor  Harvard versus von Neumann architecture  Different busses for instructions and data • ICode bus - Fetch op codes from ROM • System bus - Data from RAM and I/O • Dcode bus - Debugging • PPB bus - Private peripherals 𝐴 = 𝜋𝑟2
  • 5. Texas Instruments | ARM Cortex M - Architecture Reduced Instruction Set Computer (RISC) 4 RISC machine • Pipelining provides single cycle operation for many instructions • Thumb-2 configuration employs both 16 and 32-bit instructions CISC RISC Many instructions Few instructions Instructions have varying lengths Instructions have fixed lengths Instructions execute in varying times Instructions execute in 1 or 2 bus cycles Many instructions can access memory Few instructions can access memory  Load from memory to a register  Store from register to memory In one instruction, the processor can both • Read memory and • Write memory  No one instruction can both read and write memory in the same instruction Fewer and more specialized registers • Some registers contain data • Others contain addresses  Many identical general purpose registers Many different types of addressing modes Limited number of addressing modes  Register, PC - relative  Immediate  Indexed
  • 6. Texas Instruments | ARM Cortex M - Architecture Registers 5 32 bits wide Stack Link Program Condition Code Bits Indicates N negative Result is negative Z zero Result is zero V overflow Signed overflow C carry Unsigned overflow Where are data?  Registers  RAM  ROM  I/O ports Where are commands?  ROM (pointed to by PC)
  • 7. Texas Instruments | ARM Cortex M - Architecture Memory Map 6 8 bits wide For the detailed Memory Map go to http://www.ti.com/lit/ds/symlink/msp432p401r.pdf
  • 8. Texas Instruments | ARM Cortex M - Architecture Endianness 7 16-bit 1000 = 0x03E8 32-bit 1000000 = 0x000F4240 ASCII string “Jon” = 0x4A,0x6F,0x6E,0x00
  • 9. Texas Instruments | ARM Cortex M - Architecture Addressing Modes: immediate 8 MOV R0,#100 Register Immediate Indexed PC-relative
  • 10. Texas Instruments | ARM Cortex M - Architecture Addressing Modes: Indexed 9 LDR R0,[R1] Register Immediate Indexed PC-relative
  • 11. Texas Instruments | ARM Cortex M - Architecture Addressing Modes: Indexed 10 LDR R0,[R1,#4] Register Immediate Indexed PC-relative
  • 12. Texas Instruments | ARM Cortex M - Architecture Variable Access: Load/store architecture 11 Increment: .asmfunc LDR R1,CountAddr ; R1=pointer to Count LDR R0,[R1] ; R0=value of Count ADD R0,R0,#1 STR R0,[R1] BX LR .endasmfunc CountAddr .field Count,32 [PC,#8] 0x20000000 uint32_t Count; void Increment(void){ Count++; } Register Immediate Indexed PC-relative
  • 13. Texas Instruments | ARM Cortex M - Architecture ARM Cortex M Architecture 12 Summary  Architecture • Buses • Registers • Memory • Addressing modes Terms: • RISC vs CISC • Little vs big endian • Address vs data • Variables Register Immediate Indexed PC-relative
  • 14. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Module 3 Lecture: ARM Cortex M Assembly Programming
  • 15. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming 2 You will learn in this module  Assembly Programming • Logical and shift operations • Addition, subtraction, multiplication and divide • Accessing memory • Stack • Functions, parameters • Conditionals • Loops ARM Cortex M Assembly Programming
  • 16. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming 3 A Rn B Operand2 A&B AND A|B ORR A^B EOR 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 ORR R0,R1,R2 R1 0001 0010 0011 0100 0101 0110 0111 1000 R2 1000 0111 0110 0101 0100 0011 0010 0001 ORR 1001 0111 0111 0101 0101 0111 0111 1001 <op2> • Register • Register, shifted • Constant AND {Rd,} Rn, <op2> ;Rd=Rn&op2 ORR {Rd,} Rn, <op2> ;Rd=Rn|op2 EOR {Rd,} Rn, <op2> ;Rd=Rn^op2 Logic Operations
  • 17. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Shift Operations 4 LSR Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned) LSR Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned) ASR Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed) ASR Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed) LSL Rd, Rm, Rs ; shift left Rd=Rm<<Rs (signed, unsigned) LSL Rd, Rm, #n ; shift left Rd=Rm<<n (signed, unsigned)
  • 18. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Arithmetic Operations 5  Addition/subtraction • Two n-bit → n+1 bits  Multiplication • Two n-bit → 2n bits  Avoid overflow • Restrict input values • Promote to higher, perform, check, demote  Division • Avoid divide by 0 • Watch for dropout  Signed versus unsigned • Either signed or unsigned, not both • Be careful about converting types
  • 19. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Addition and Subtraction 6 ADD {Rd,} Rn, <op2> ;Rd = Rn + op2 SUB {Rd,} Rn, <op2> ;Rd = Rn - op2 CMP Rn, <op2> ;Rn - op2 Sets the carry bit Condition Code Bits Indicates N negative Result is negative Z zero Result is zero V overflow Signed overflow C carry Unsigned overflow <op2> • Register • Register, shifted • Constant
  • 20. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Multiplication and Division 7 uint32_t N,M; // times 0.6 void Fun(void){ M = 3*N/5; } .data .align 2 N .space 4 M .space 4 .text .align 2 Fun: .asmfunc LDR R3, Naddr ; R3 = &N (R3 points to N) LDR R1, [R3] ; R1 = N MOV R0, #3 ; R0 = 3 MUL R1, R0, R1 ; R1 = 3*N MOV R0, #5 ; R0 = 5 UDIV R0, R1, R0 ; R0 = 3*N/5 LDR R2, MAddr ; R2 = &M (R2 points to M) STR R0, [R2] ; M = 3*N/5 BX LR .endasmfunc NAddr .field N,32 MAddr .field M,32 MUL {Rd,} Rn, Rm ;Rd = Rn * Rm UDIV {Rd,} Rn, Rm ;Rd = Rn/Rm unsigned SDIV {Rd,} Rn, Rm ;Rd = Rn/Rm signed
  • 21. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Stack 8 PUSH {R0} PUSH {R1} PUSH {R2} POP {R3} POP {R4} POP {R5} Push 1. SP=SP-4 2. Store at SP POP 1. Read at SP 2. SP=SP+4 Usage • Temporary storage • Local variables
  • 22. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming // random.c uint32_t static M; void Seed(uint32_t x){ M = x; } uint8_t Rand(void){ M=1664525*M+1013904223; return M>>24; } Function calls 9 .data .align 2 M .space 4 .text .align 2 Seed: .asmfunc LDR R1,MAddr ; R1=&M STR R0,[R1] ; set M BX LR .endasmfunc Rand: .asmfunc LDR R2,MAddr ; R2=&M, address of M LDR R0,[R2] ; R0=M, value of M LDR R1,Slope MUL R0,R0,R1 ; R0 = 1664525*M LDR R1,Offst ADD R0,R0,R1 ; 1664525*M+1013904223 STR R0,[R2] ; store M LSR R0,#24 ; 0 to 255 BX LR .endasmfunc MAddr .field M,32 Slope .field 1664525,32 Offst .field 1013904223,32 .data .align 2 n .space 4 .text .align 2 main: .asmfunc MOV R0,#1 BL Seed loop BL Rand LDR R1,nAddr STR R0,[R1] B loop .endasmfunc nAddr .field n,32
  • 23. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming Conditionals 10 LDR R3,G2Addr ; R3=&G2, address of G2 LDR R2,[R3] ; R2=G2, value of G2 LDR R0,G1Addr ; R0=&G1, address of G1 LDR R1,[R0] ; R1=G1, value of G1 CMP R1,R2 ; compare G1 G2 BHI isNo isYes BL Yes ; G1<=G2 B done isNo BL No done G1Addr .field G1,32 G2Addr .field G2,32 Instruction Branch if B target ; always BEQ target ; equal (signed or unsigned) BNE target ; not equal (signed or unsigned) BLO target ; unsigned less than BLS target ; unsigned less than or equal to BHS target ; unsigned greater than or equal to BHI target ; unsigned greater than BLT target ; signed less than BGE target ; signed greater than or equal to BGT target ; signed greater than BLE target ; signed less than or equal to if(G2<=G1){ Yes(); }else{ No(); } Think of the three steps 1) bring first value into a register, 2) compare to second value, 3) conditional branch, bxx (where xx is eq ne lo ls hi hs gt ge lt or le). The branch will occur if (first is xx second).
  • 24. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming While Loops 11 while(G2>G1){ Body(); } LDR R3,G2Addr ; R3=&G2, address of G2 LDR R2,[R3] ; R2=G2, value of G2 LDR R0,G1Addr ; R0=&G1, address of G1 LDR R1,[R0] ; R1=G1, value of G1 loop CMP R1,R2 ; compare G1 G2 BLS done BL Body ; G1>G2 B loop done G1Addr .field G1,32 ;unsigned 32-bit number G2Addr .field G2,32 ;unsigned 32-bit number
  • 25. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming For Loops 12 MOV R4,#10 loop BL Body SUBS R4,R4,#1 BNE loop MOV R4,#10 loop CMP R4,#0 BEQ done BL Body SUB R4,R4,#1 B loop done for(i=10; i!=0; i--){ Body(); // 10 times }
  • 26. Texas Instruments Robotics System Learning Kit: The Maze Edition SWRP141 | ARM Cortex M - Assembly Programming ARM Cortex M Assembly Programming 13 Summary  Programming • Accessing memory • Logical and shift operations • Addition, subtraction, multiplication and divide • Stack • Functions, parameters • Conditionals • Loops Register Immediate Indexed PC-relative
  • 27. IMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCES Texas Instruments Incorporated (‘TI”) technical, application or other design advice, services or information, including, but not limited to, reference designs and materials relating to evaluation modules, (collectively, “TI Resources”) are intended to assist designers who are developing applications that incorporate TI products; by downloading, accessing or using any particular TI Resource in any way, you (individually or, if you are acting on behalf of a company, your company) agree to use it solely for this purpose and subject to the terms of this Notice. TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI products, and no additional obligations or liabilities arise from TI providing such TI Resources. TI reserves the right to make corrections, enhancements, improvements and other changes to its TI Resources. You understand and agree that you remain responsible for using your independent analysis, evaluation and judgment in designing your applications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications (and of all TI products used in or for your applications) with all applicable regulations, laws and other applicable requirements. You represent that, with respect to your applications, you have all the necessary expertise to create and implement safeguards that (1) anticipate dangerous consequences of failures, (2) monitor failures and their consequences, and (3) lessen the likelihood of failures that might cause harm and take appropriate actions. You agree that prior to using or distributing any applications that include TI products, you will thoroughly test such applications and the functionality of such TI products as used in such applications. TI has not conducted any testing other than that specifically described in the published documentation for a particular TI Resource. You are authorized to use, copy and modify any individual TI Resource only in connection with the development of applications that include the TI product(s) identified in such TI Resource. NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE TO ANY OTHER TI INTELLECTUAL PROPERTY RIGHT, AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTY RIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN, including but not limited to any patent right, copyright, mask work right, or other intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information regarding or referencing third-party products or services does not constitute a license to use such products or services, or a warranty or endorsement thereof. Use of TI Resources may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI. TI RESOURCES ARE PROVIDED “AS IS” AND WITH ALL FAULTS. TI DISCLAIMS ALL OTHER WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, REGARDING TI RESOURCES OR USE THEREOF, INCLUDING BUT NOT LIMITED TO ACCURACY OR COMPLETENESS, TITLE, ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHTS. TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM, INCLUDING BUT NOT LIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IF DESCRIBED IN TI RESOURCES OR OTHERWISE. IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, COLLATERAL, INDIRECT, PUNITIVE, INCIDENTAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH OR ARISING OUT OF TI RESOURCES OR USE THEREOF, AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You agree to fully indemnify TI and its representatives against any damages, costs, losses, and/or liabilities arising out of your non- compliance with the terms and provisions of this Notice. This Notice applies to TI Resources. Additional terms apply to the use and purchase of certain types of materials, TI products and services. These include; without limitation, TI’s standard terms for semiconductor products http://www.ti.com/sc/docs/stdterms.htm), evaluation modules, and samples (http://www.ti.com/sc/docs/sampterms.htm). Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265 Copyright © 2018, Texas Instruments Incorporated