SlideShare a Scribd company logo
1 of 46
Dr. Yifeng Zhu
Electrical and Computer Engineering
University of Maine
Spring 2018
Embedded Systems with ARM Cortex-M Microcontrollers in Assembly Language and C
Chapter 1
Computer and Assembly Language
1
Embedded Systems
2
Amazon Warehouse
3
Kiva Robot
4
Assembly Programs
http://www.andysinger.com/
Why do we learn Assembly?
 Assembly isn’t “just another language”.
 Help you understand how does the processor work
 Assembly program runs faster than high-level language. Performance critical codes must be
written in assembly.
 Use the profiling tools to find the performance bottle and rewrite that code section in assembly
 Latency-sensitive applications, such as aircraft controller
 Standard C compilers do not use some operations available on ARM processors, such ROR (Rotate
Right) and RRX (Rotate Right Extended).
 Hardware/processor specific code,
 Processor booting code
 Device drivers
 A test-and-set atomic assembly instruction can be used to implement locks and semaphores.
 Cost-sensitive applications
 Embedded devices, where the size of code is limited, wash machine controller, automobile controllers
 The best applications are written by those who've mastered assembly language or fully
understand the low-level implementation of the high-level language statements they're
choosing.
5
Why ARM processor
6
 As of 2005, 98% of the more than one billion mobile
phones sold each year used ARM processors
 As of 2009, ARM processors accounted for approximately
90% of all embedded 32-bit RISC processors
 In 2010 alone, 6.1 billion ARM-based processor,
representing 95% of smartphones, 35% of digital
televisions and set-top boxes and 10% of mobile
computers
 As of 2014, over 50 billion ARM processors have been
produced
iPhone 7
Teardown
7
A10 processor:
• 64-bit system on chip
(SoC)
• ARMv8-A core
Apple Watch
8
 Apple S1 Processor
 32-bit ARMv7-A compatible
 # of Cores: 1
 CMOS Technology: 28 nm
 L1 cache 32 KB data
 L2 cache 256 KB
 GPU PowerVR SGX543
Kindle HD Fire
9 http://www.ifixit.com
Texas Instruments
OMAP 4460 dual-
core processor
Fitbit Flex Teardown
10
STMicroelectronics
32L151C6 Ultra Low
Power ARM Cortex M3
Microcontroller
Nordic Semiconductor
nRF8001 Bluetooth Low
Energy Connectivity IC
www.ifixit.com
Samsung Galaxy Gear
 STMicroelectronics
STM32F401B ARM-
Cortex M4 MCU with
128KB Flash
source: ifixit.com
11
Pebble Smartwatch
 STMicroelectronics STM32F205RE
ARM Cortex-M3 MCU, with a maximum
speed of 120 MHz
source: ifixit.com
12
Oculus VR
 Facebook’s $2 Billion Acquisition Of Oculus in 2014
 ST Microelectronics STM32F072VB ARM Cortex-M0 32-bit RISC
Core Microcontroller
source: ifixit.com
13
HTC Vive
14
STMicroelectronics
32F072R8 ARM Cortex-M0
Microcontroller
source: ifixit.com
Nest Learning Thermostat
 ST Microelectronics STM32L151VB ultra-low-power 32 MHz
ARM Cortex-M3 MCU
source: ifixit.com
15
Samsung Gear Fit Fitness Tracker
 STMicroelectronics STM32F439ZI 180
MHz, 32 bit ARM Cortex-M4 CPU
source: ifixit.com
16
Memory
 Memory is arranged as a series of
“locations”
 Each location has a unique “address”
 Each location holds a byte (byte-addressable)
 e.g. the memory location at address
0x080001B0 contains the byte value 0x70, i.e.,
112
 The number of locations in memory is
limited
 e.g. 4 GB of RAM
 1 Gigabyte (GB) = 230 bytes
 232 locations  4,294,967,296 locations!
 Values stored at each location can
represent either program data or program
instructions
 e.g. the value 0x70 might be the code used to
17
70
BC
18
01
A0
0x00000000
0xFFFFFFFF
0x080001B0
0x080001AF
0x080001AE
0x080001AD
0x080001AC
Memory
Address
Data
8 bits 32 bits
18
Computer Architecture
Instructions and data are
stored in the same memory.
Von-Neumann Harvard
Data and instructions are
stored into separate memories.
19
Computer Architecture
Instructions and data are
stored in the same memory.
Von-Neumann Harvard
Data and instructions are
stored into separate memories.
ARM Cortex-M Series Family
20
Instructions and data are
stored in the same memory.
Von-Neumann Harvard
Data and instructions are
stored into separate memories.
ARM
Cortex-M0
ARM
Cortex-M1
ARM
Cortex-M0+
ARM
Cortex-M23
ARM
Cortex-M3
ARM
Cortex-M7
ARM
Cortex-M4
ARM
Cortex-M33
ARMv6-M ARMv6-M
ARMv6-M ARMv8-M
ARMv7-M ARMv7E-M
ARMv7E-M ARMv8-M
Levels of Program Code
21
 High-level language
 Level of abstraction
closer to problem
domain
 Provides for
productivity and
portability
C Program
Compile Assemble
Assembly Program
 Assembly language
 Textual
representation of
instructions
Machine Program
 Hardware
representation
 Binary digits
(bits)
 Encoded
instructions
and data
0010000100000000
0010000000000000
1110000000000001
0100010000000001
0001110001000000
0010100000001010
1101110011111011
1011111100000000
1110011111111110
int main(void){
int i;
int total = 0;
for (i = 0; i < 10; i++) {
total += i;
}
while(1); // Dead loop
}
See a Program Runs
int main(void){
int a = 0;
int b = 1;
int c;
c = a + b;
return 0;
}
22
C Code
compiler
MOVS r1, #0x00 ; int a = 0
MOVS r2, #0x01 ; int b = 1
ADDS r3, r1, r2 ; c = a + b
MOVS r0, 0x00 ; set return value
BX lr ; return
Assembly Code
00100001000000
00
00100010000000
01
00011000100010
11
00100000000000
00
010001110111000
Machine Code
In Binary
; MOVS r1,
#0x00
; MOVS r2,
#0x01
; ADDS r3, r1, r2
; MOVS r0,
#0x00
; BX lr
2100
2201
188B
2000
4770
In Hex
Processor Registers
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 (SP)
R14 (LR)
R15 (PC)
32 bits
CONTROL
FAULTMASK
PRIMASK
BASEPRI
R13 (MSP) R13 (PSP)
xPSR
Low
Registers
High
Registers
32 bits
Special
Purpose
Register
General
Purpose
Register
23
 Fastest way to read and write
 Registers are within the processor chip
 A register stores 32-bit value
 STM32L has
 R0-R12: 13 general-purpose registers
 R13: Stack pointer (Shadow of MSP or PSP)
 R14: Link register (LR)
 R15: Program counter (PC)
 Special registers (xPSR, BASEPRI,
PRIMASK, etc)
Program Execution
 Program Counter (PC) is a register that holds the memory
address of the next instruction to be fetched from the memory.
1. Fetch
instruction at
PC address
2. Decode
the
instruction
3. Execute
the
instruction
4770
2000
188B
2201
2100
0x080001B4
0x080001B2
0x080001B0
0x080001AE
0x080001AC
PC
Memory Address
24
PC = 0x080001B0
Instruction = 188B or
2000188B or 8B180020
Three-state pipeline:
Fetch, Decode, Execution
 Pipelining allows hardware resources to be fully utilized
 One 32-bit instruction or two 16-bit instructions can be fetched.
25
Pipeline of 32-bit instructions
Three-state pipeline:
Fetch, Decode, Execution
 Pipelining allows hardware resources to be fully utilized
 One 32-bit instruction or two 16-bit instructions can be fetched.
26
Pipeline of 16-bit instructions
Instruction i
Instruction
Fetch
Instruction
Decode
Instruction
Execution
Instruction
Fetch
Instruction
Decode
Instruction
Execution
Instruction
Fetch
Instruction
Decode
Instruction
Execution
Clock
Instruction i + 1
Instruction i + 2
Instruction
Fetch
Instruction
Decode
Instruction
Execution
Instruction i + 2
Machine codes are stored in memory
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
Registers Memory
Address
Data
CPU
27
Fetch Instruction: pc = 0x08001AC
Decode Instruction: 2100 = MOVS r1, #0x00
0x080001A
C
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
28
Execute Instruction:
MOVS r1, #0x00
0x080001A
C
0x0000000
0
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
29
Fetch Next Instruction: pc = pc + 2
Decode & Execute: 2201 = MOVS r2, #0x01
0x080001A
E
0x0000000
1
0x0000000
0
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
30
Fetch Next Instruction: pc = pc + 2
Decode & Execute: 188B = ADDS r3, r1, r2
0x080001B
0
0x0000000
1
0x0000000
1
0x0000000
0
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
31
Fetch Next Instruction: pc = pc + 2
Decode & Execute: 2000 = MOVS r0, #0x00
0x080001B
2
0x0000000
1
0x0000000
0
0x0000000
0
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
32
Fetch Next Instruction: pc = pc + 2
Decode & Decode: 4770 = BX lr
0x080001B
4
0x0000000
1
0x0000000
0
0x0000000
0
r15
r14
r13
r12
r11
r10
r9
r8
r7
r6
r5
r4
r3
r2
r1
r0
ALU
477
0
200
0
188
B
220
1
210
0
pc
lr
sp
0x00000000
0xFFFFFFFF
Registers Memory
Address
Data
CPU
0x080001B
4
0x080001B
2
0x080001B
0
0x080001A
E
0x080001A
C
33
Example:
Calculate the Sum of an Array
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int total;
int main(void){
int i;
total = 0;
for (i = 0; i < 10; i++) {
total += a[i];
}
while(1);
}
34
Example:
Calculate the Sum of an Array
CPU I/O Devices
Data
Memory (RAM)
Instruction
Memory (Flash)
int main(void){
int i;
total = 0;
for (i = 0; i < 10; i++) {
total += a[i];
}
while(1);
}
int a[10] = {1, 2, 3, 4, 5, 6, 7,
8, 9, 10};
int total;
Starting memory address
0x08000000
Starting memory address
0x20000000
35
Example:
Calculate the Sum of an Array
Instruction
Memory (Flash)
int main(void){
int i;
total = 0;
for (i = 0; i < 10; i++) {
total += a[i];
}
while(1);
}
Starting memory address
0x08000000
0010 0001 0000 0000
0100 1010 0000 1000
0110 0000 0001 0001
0010 0000 0000 0000
1110 0000 0000 1000
0100 1001 0000 0111
1111 1000 0101 0001
0001 0000 0010 0000
0100 1010 0000 0100
0110 1000 0001 0010
0100 0100 0001 0001
0100 1010 0000 0011
0110 0000 0001 0001
0001 1100 0100 0000
0010 1000 0000 1010
1101 1011 1111 0100
1011 1111 0000 0000
1110 0111 1111 1110
MOVS r1, #0x00
LDR r2, = total_addr
STR r1, [r2, #0x00]
MOVS r0, #0x00
B Check
Loop: LDR r1, = a_addr
LDR r1, [r1, r0, LSL #2]
LDR r2, = total_addr
LDR r2, [r2, #0x00]
ADD r1, r1, r2
LDR r2, = total_addr
STR r1, [r2,#0x00]
ADDS r0, r0, #1
Check: CMP r0, #0x0A
BLT Loop
NOP
Self: B Self
36
Example:
Calculate the Sum of an Array
0x0001
0x0000
0x0002
0x0000
0x0003
0x0000
0x0004
0x0000
0x0005
0x0000
0x0006
0x0000
0x0007
0x0000
0x0008
0x0000
0x0009
0x0000
0x000A
0x0000
0x0000
0x0000
Data
Memory (RAM)
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int total;
Assume the starting memory address of
the data memory is 0x20000000
0x20000000
0x20000002
0x20000004
0x20000006
0x20000008
0x2000000A
0x2000000C
0x2000000E
0x20000010
0x20000012
0x20000014
0x20000016
0x20000018
0x2000001A
0x2000001C
0x2000001E
0x20000020
0x20000022
0x20000024
0x20000026
0x20000028
0x2000002A
Memory
address
in bytes
Memory
content
a[0] = 0x00000001
a[1] = 0x00000002
a[2] = 0x00000003
a[3] = 0x00000004
a[4] = 0x00000005
a[5] = 0x00000006
a[6] = 0x00000007
a[7] = 0x00000008
a[8] = 0x00000009
a[9] = 0x0000000A
total= 0x00000000
37
Loading Code and Data into Memory
38
Loading Code and Data into Memory
39
Loading Code and Data into Memory
40
• Stack is mandatory
• Heap is used only if
dynamic allocation (e.g.
malloc, calloc) is used.
View of a Binary Program
41
42
from st.com
43
from st.com
44
from st.com
45
STM32L4
from st.com
Memory
Map
46

More Related Content

Similar to Chapter_01_See_Program_Running.pptx

Lecture 5-Embedde.pdf
Lecture 5-Embedde.pdfLecture 5-Embedde.pdf
Lecture 5-Embedde.pdfBlackHunter13
 
arm 7 microprocessor architecture ans pin diagram.ppt
arm 7 microprocessor architecture ans pin diagram.pptarm 7 microprocessor architecture ans pin diagram.ppt
arm 7 microprocessor architecture ans pin diagram.pptmanikandan970975
 
16-bit Microprocessor Design (2005)
16-bit Microprocessor Design (2005)16-bit Microprocessor Design (2005)
16-bit Microprocessor Design (2005)Susam Pal
 
iPhone Architecture - Review
iPhone Architecture - ReviewiPhone Architecture - Review
iPhone Architecture - ReviewAbdelrahman Hosny
 
Powerful SoM based on i.MX 8M Mini processor for various embedded applications
Powerful SoM based on i.MX 8M Mini processor for various embedded applicationsPowerful SoM based on i.MX 8M Mini processor for various embedded applications
Powerful SoM based on i.MX 8M Mini processor for various embedded applicationsnie, jack
 
AAME ARM Techcon2013 003v02 Software Development
AAME ARM Techcon2013 003v02  Software DevelopmentAAME ARM Techcon2013 003v02  Software Development
AAME ARM Techcon2013 003v02 Software DevelopmentAnh Dung NGUYEN
 
Developing an avr microcontroller system
Developing an avr microcontroller systemDeveloping an avr microcontroller system
Developing an avr microcontroller systemnugnugmacmac
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationTalal Khaliq
 
Assembly chapter One.pptx
Assembly chapter One.pptxAssembly chapter One.pptx
Assembly chapter One.pptxssuserb78e291
 
ATmega32-AVR microcontrollers-Part I
ATmega32-AVR microcontrollers-Part IATmega32-AVR microcontrollers-Part I
ATmega32-AVR microcontrollers-Part IVineethMP2
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28rajeshkvdn
 
Embedded System - Dtmf robot
Embedded System - Dtmf robotEmbedded System - Dtmf robot
Embedded System - Dtmf robotAbhishek Sood
 
Q4.11: ARM Technology Update Plenary
Q4.11: ARM Technology Update PlenaryQ4.11: ARM Technology Update Plenary
Q4.11: ARM Technology Update PlenaryLinaro
 
Arm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armArm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armPrashant Ahire
 
Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Amogha Bandrikalli
 
Introduction to-microprocessors
Introduction to-microprocessorsIntroduction to-microprocessors
Introduction to-microprocessorsVolodymyr Ushenko
 
Rico board
Rico boardRico board
Rico boardmyirtech
 
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...Toradex
 

Similar to Chapter_01_See_Program_Running.pptx (20)

Lecture 5-Embedde.pdf
Lecture 5-Embedde.pdfLecture 5-Embedde.pdf
Lecture 5-Embedde.pdf
 
arm 7 microprocessor architecture ans pin diagram.ppt
arm 7 microprocessor architecture ans pin diagram.pptarm 7 microprocessor architecture ans pin diagram.ppt
arm 7 microprocessor architecture ans pin diagram.ppt
 
16-bit Microprocessor Design (2005)
16-bit Microprocessor Design (2005)16-bit Microprocessor Design (2005)
16-bit Microprocessor Design (2005)
 
Assignment
AssignmentAssignment
Assignment
 
iPhone Architecture - Review
iPhone Architecture - ReviewiPhone Architecture - Review
iPhone Architecture - Review
 
Powerful SoM based on i.MX 8M Mini processor for various embedded applications
Powerful SoM based on i.MX 8M Mini processor for various embedded applicationsPowerful SoM based on i.MX 8M Mini processor for various embedded applications
Powerful SoM based on i.MX 8M Mini processor for various embedded applications
 
ELECTRONIC AND - Copy (1)
ELECTRONIC AND - Copy (1)ELECTRONIC AND - Copy (1)
ELECTRONIC AND - Copy (1)
 
AAME ARM Techcon2013 003v02 Software Development
AAME ARM Techcon2013 003v02  Software DevelopmentAAME ARM Techcon2013 003v02  Software Development
AAME ARM Techcon2013 003v02 Software Development
 
Developing an avr microcontroller system
Developing an avr microcontroller systemDeveloping an avr microcontroller system
Developing an avr microcontroller system
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
 
Assembly chapter One.pptx
Assembly chapter One.pptxAssembly chapter One.pptx
Assembly chapter One.pptx
 
ATmega32-AVR microcontrollers-Part I
ATmega32-AVR microcontrollers-Part IATmega32-AVR microcontrollers-Part I
ATmega32-AVR microcontrollers-Part I
 
My seminar new 28
My seminar new 28My seminar new 28
My seminar new 28
 
Embedded System - Dtmf robot
Embedded System - Dtmf robotEmbedded System - Dtmf robot
Embedded System - Dtmf robot
 
Q4.11: ARM Technology Update Plenary
Q4.11: ARM Technology Update PlenaryQ4.11: ARM Technology Update Plenary
Q4.11: ARM Technology Update Plenary
 
Arm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armArm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_arm
 
Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller Module 1 - ARM 32 Bit Microcontroller
Module 1 - ARM 32 Bit Microcontroller
 
Introduction to-microprocessors
Introduction to-microprocessorsIntroduction to-microprocessors
Introduction to-microprocessors
 
Rico board
Rico boardRico board
Rico board
 
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
First Steps Developing Embedded Applications using Heterogeneous Multi-core P...
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 

Chapter_01_See_Program_Running.pptx

  • 1. Dr. Yifeng Zhu Electrical and Computer Engineering University of Maine Spring 2018 Embedded Systems with ARM Cortex-M Microcontrollers in Assembly Language and C Chapter 1 Computer and Assembly Language 1
  • 5. Why do we learn Assembly?  Assembly isn’t “just another language”.  Help you understand how does the processor work  Assembly program runs faster than high-level language. Performance critical codes must be written in assembly.  Use the profiling tools to find the performance bottle and rewrite that code section in assembly  Latency-sensitive applications, such as aircraft controller  Standard C compilers do not use some operations available on ARM processors, such ROR (Rotate Right) and RRX (Rotate Right Extended).  Hardware/processor specific code,  Processor booting code  Device drivers  A test-and-set atomic assembly instruction can be used to implement locks and semaphores.  Cost-sensitive applications  Embedded devices, where the size of code is limited, wash machine controller, automobile controllers  The best applications are written by those who've mastered assembly language or fully understand the low-level implementation of the high-level language statements they're choosing. 5
  • 6. Why ARM processor 6  As of 2005, 98% of the more than one billion mobile phones sold each year used ARM processors  As of 2009, ARM processors accounted for approximately 90% of all embedded 32-bit RISC processors  In 2010 alone, 6.1 billion ARM-based processor, representing 95% of smartphones, 35% of digital televisions and set-top boxes and 10% of mobile computers  As of 2014, over 50 billion ARM processors have been produced
  • 7. iPhone 7 Teardown 7 A10 processor: • 64-bit system on chip (SoC) • ARMv8-A core
  • 8. Apple Watch 8  Apple S1 Processor  32-bit ARMv7-A compatible  # of Cores: 1  CMOS Technology: 28 nm  L1 cache 32 KB data  L2 cache 256 KB  GPU PowerVR SGX543
  • 9. Kindle HD Fire 9 http://www.ifixit.com Texas Instruments OMAP 4460 dual- core processor
  • 10. Fitbit Flex Teardown 10 STMicroelectronics 32L151C6 Ultra Low Power ARM Cortex M3 Microcontroller Nordic Semiconductor nRF8001 Bluetooth Low Energy Connectivity IC www.ifixit.com
  • 11. Samsung Galaxy Gear  STMicroelectronics STM32F401B ARM- Cortex M4 MCU with 128KB Flash source: ifixit.com 11
  • 12. Pebble Smartwatch  STMicroelectronics STM32F205RE ARM Cortex-M3 MCU, with a maximum speed of 120 MHz source: ifixit.com 12
  • 13. Oculus VR  Facebook’s $2 Billion Acquisition Of Oculus in 2014  ST Microelectronics STM32F072VB ARM Cortex-M0 32-bit RISC Core Microcontroller source: ifixit.com 13
  • 14. HTC Vive 14 STMicroelectronics 32F072R8 ARM Cortex-M0 Microcontroller source: ifixit.com
  • 15. Nest Learning Thermostat  ST Microelectronics STM32L151VB ultra-low-power 32 MHz ARM Cortex-M3 MCU source: ifixit.com 15
  • 16. Samsung Gear Fit Fitness Tracker  STMicroelectronics STM32F439ZI 180 MHz, 32 bit ARM Cortex-M4 CPU source: ifixit.com 16
  • 17. Memory  Memory is arranged as a series of “locations”  Each location has a unique “address”  Each location holds a byte (byte-addressable)  e.g. the memory location at address 0x080001B0 contains the byte value 0x70, i.e., 112  The number of locations in memory is limited  e.g. 4 GB of RAM  1 Gigabyte (GB) = 230 bytes  232 locations  4,294,967,296 locations!  Values stored at each location can represent either program data or program instructions  e.g. the value 0x70 might be the code used to 17 70 BC 18 01 A0 0x00000000 0xFFFFFFFF 0x080001B0 0x080001AF 0x080001AE 0x080001AD 0x080001AC Memory Address Data 8 bits 32 bits
  • 18. 18 Computer Architecture Instructions and data are stored in the same memory. Von-Neumann Harvard Data and instructions are stored into separate memories.
  • 19. 19 Computer Architecture Instructions and data are stored in the same memory. Von-Neumann Harvard Data and instructions are stored into separate memories.
  • 20. ARM Cortex-M Series Family 20 Instructions and data are stored in the same memory. Von-Neumann Harvard Data and instructions are stored into separate memories. ARM Cortex-M0 ARM Cortex-M1 ARM Cortex-M0+ ARM Cortex-M23 ARM Cortex-M3 ARM Cortex-M7 ARM Cortex-M4 ARM Cortex-M33 ARMv6-M ARMv6-M ARMv6-M ARMv8-M ARMv7-M ARMv7E-M ARMv7E-M ARMv8-M
  • 21. Levels of Program Code 21  High-level language  Level of abstraction closer to problem domain  Provides for productivity and portability C Program Compile Assemble Assembly Program  Assembly language  Textual representation of instructions Machine Program  Hardware representation  Binary digits (bits)  Encoded instructions and data 0010000100000000 0010000000000000 1110000000000001 0100010000000001 0001110001000000 0010100000001010 1101110011111011 1011111100000000 1110011111111110 int main(void){ int i; int total = 0; for (i = 0; i < 10; i++) { total += i; } while(1); // Dead loop }
  • 22. See a Program Runs int main(void){ int a = 0; int b = 1; int c; c = a + b; return 0; } 22 C Code compiler MOVS r1, #0x00 ; int a = 0 MOVS r2, #0x01 ; int b = 1 ADDS r3, r1, r2 ; c = a + b MOVS r0, 0x00 ; set return value BX lr ; return Assembly Code 00100001000000 00 00100010000000 01 00011000100010 11 00100000000000 00 010001110111000 Machine Code In Binary ; MOVS r1, #0x00 ; MOVS r2, #0x01 ; ADDS r3, r1, r2 ; MOVS r0, #0x00 ; BX lr 2100 2201 188B 2000 4770 In Hex
  • 23. Processor Registers R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (SP) R14 (LR) R15 (PC) 32 bits CONTROL FAULTMASK PRIMASK BASEPRI R13 (MSP) R13 (PSP) xPSR Low Registers High Registers 32 bits Special Purpose Register General Purpose Register 23  Fastest way to read and write  Registers are within the processor chip  A register stores 32-bit value  STM32L has  R0-R12: 13 general-purpose registers  R13: Stack pointer (Shadow of MSP or PSP)  R14: Link register (LR)  R15: Program counter (PC)  Special registers (xPSR, BASEPRI, PRIMASK, etc)
  • 24. Program Execution  Program Counter (PC) is a register that holds the memory address of the next instruction to be fetched from the memory. 1. Fetch instruction at PC address 2. Decode the instruction 3. Execute the instruction 4770 2000 188B 2201 2100 0x080001B4 0x080001B2 0x080001B0 0x080001AE 0x080001AC PC Memory Address 24 PC = 0x080001B0 Instruction = 188B or 2000188B or 8B180020
  • 25. Three-state pipeline: Fetch, Decode, Execution  Pipelining allows hardware resources to be fully utilized  One 32-bit instruction or two 16-bit instructions can be fetched. 25 Pipeline of 32-bit instructions
  • 26. Three-state pipeline: Fetch, Decode, Execution  Pipelining allows hardware resources to be fully utilized  One 32-bit instruction or two 16-bit instructions can be fetched. 26 Pipeline of 16-bit instructions Instruction i Instruction Fetch Instruction Decode Instruction Execution Instruction Fetch Instruction Decode Instruction Execution Instruction Fetch Instruction Decode Instruction Execution Clock Instruction i + 1 Instruction i + 2 Instruction Fetch Instruction Decode Instruction Execution Instruction i + 2
  • 27. Machine codes are stored in memory r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C Registers Memory Address Data CPU 27
  • 28. Fetch Instruction: pc = 0x08001AC Decode Instruction: 2100 = MOVS r1, #0x00 0x080001A C r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 28
  • 29. Execute Instruction: MOVS r1, #0x00 0x080001A C 0x0000000 0 r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 29
  • 30. Fetch Next Instruction: pc = pc + 2 Decode & Execute: 2201 = MOVS r2, #0x01 0x080001A E 0x0000000 1 0x0000000 0 r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 30
  • 31. Fetch Next Instruction: pc = pc + 2 Decode & Execute: 188B = ADDS r3, r1, r2 0x080001B 0 0x0000000 1 0x0000000 1 0x0000000 0 r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 31
  • 32. Fetch Next Instruction: pc = pc + 2 Decode & Execute: 2000 = MOVS r0, #0x00 0x080001B 2 0x0000000 1 0x0000000 0 0x0000000 0 r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 32
  • 33. Fetch Next Instruction: pc = pc + 2 Decode & Decode: 4770 = BX lr 0x080001B 4 0x0000000 1 0x0000000 0 0x0000000 0 r15 r14 r13 r12 r11 r10 r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 ALU 477 0 200 0 188 B 220 1 210 0 pc lr sp 0x00000000 0xFFFFFFFF Registers Memory Address Data CPU 0x080001B 4 0x080001B 2 0x080001B 0 0x080001A E 0x080001A C 33
  • 34. Example: Calculate the Sum of an Array int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int total; int main(void){ int i; total = 0; for (i = 0; i < 10; i++) { total += a[i]; } while(1); } 34
  • 35. Example: Calculate the Sum of an Array CPU I/O Devices Data Memory (RAM) Instruction Memory (Flash) int main(void){ int i; total = 0; for (i = 0; i < 10; i++) { total += a[i]; } while(1); } int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int total; Starting memory address 0x08000000 Starting memory address 0x20000000 35
  • 36. Example: Calculate the Sum of an Array Instruction Memory (Flash) int main(void){ int i; total = 0; for (i = 0; i < 10; i++) { total += a[i]; } while(1); } Starting memory address 0x08000000 0010 0001 0000 0000 0100 1010 0000 1000 0110 0000 0001 0001 0010 0000 0000 0000 1110 0000 0000 1000 0100 1001 0000 0111 1111 1000 0101 0001 0001 0000 0010 0000 0100 1010 0000 0100 0110 1000 0001 0010 0100 0100 0001 0001 0100 1010 0000 0011 0110 0000 0001 0001 0001 1100 0100 0000 0010 1000 0000 1010 1101 1011 1111 0100 1011 1111 0000 0000 1110 0111 1111 1110 MOVS r1, #0x00 LDR r2, = total_addr STR r1, [r2, #0x00] MOVS r0, #0x00 B Check Loop: LDR r1, = a_addr LDR r1, [r1, r0, LSL #2] LDR r2, = total_addr LDR r2, [r2, #0x00] ADD r1, r1, r2 LDR r2, = total_addr STR r1, [r2,#0x00] ADDS r0, r0, #1 Check: CMP r0, #0x0A BLT Loop NOP Self: B Self 36
  • 37. Example: Calculate the Sum of an Array 0x0001 0x0000 0x0002 0x0000 0x0003 0x0000 0x0004 0x0000 0x0005 0x0000 0x0006 0x0000 0x0007 0x0000 0x0008 0x0000 0x0009 0x0000 0x000A 0x0000 0x0000 0x0000 Data Memory (RAM) int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int total; Assume the starting memory address of the data memory is 0x20000000 0x20000000 0x20000002 0x20000004 0x20000006 0x20000008 0x2000000A 0x2000000C 0x2000000E 0x20000010 0x20000012 0x20000014 0x20000016 0x20000018 0x2000001A 0x2000001C 0x2000001E 0x20000020 0x20000022 0x20000024 0x20000026 0x20000028 0x2000002A Memory address in bytes Memory content a[0] = 0x00000001 a[1] = 0x00000002 a[2] = 0x00000003 a[3] = 0x00000004 a[4] = 0x00000005 a[5] = 0x00000006 a[6] = 0x00000007 a[7] = 0x00000008 a[8] = 0x00000009 a[9] = 0x0000000A total= 0x00000000 37
  • 38. Loading Code and Data into Memory 38
  • 39. Loading Code and Data into Memory 39
  • 40. Loading Code and Data into Memory 40 • Stack is mandatory • Heap is used only if dynamic allocation (e.g. malloc, calloc) is used.
  • 41. View of a Binary Program 41

Editor's Notes

  1. #define __I volatile const /*!< defines 'read only' permissions */ #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */
  2. #define __I volatile const /*!< defines 'read only' permissions */ #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */
  3. #define __I volatile const /*!< defines 'read only' permissions */ #define __O volatile /*!< defines 'write only' permissions */ #define __IO volatile /*!< defines 'read / write' permissions */
  4. 45