SlideShare a Scribd company logo
1 of 29
Download to read offline
Memory Access Instructions
Chapter 6
1 Engr.Sharif Kakar
Memory Access Instruction
 Topics Covered:
 ARM is a Load Store Architecture, all data processing instructions
are executed in registers
❖ Does not support memory to memory data processing operations.
❖ Must move data values into registers before using them
 LDR / Memory to register or LOAD from memory to register
 STR / Register to memory or STORE from register to memory
3 sets of memory access instruction
 Single register data transfer(LDR/STR)
 Block data transfer(LDM/STM)
 Single data swap (SWP)
2 Engr.Sharif Kakar
Assembly Operands: Memory
 Memory: Think of as single one-dimensional array where each
cell stores a byte size value
 Is referred to by a 32 bit address e.g. value at 0x4000 is 0x0a
 Data is stored in memory as: variables, arrays, structures
In LDR instruction we studied
 Zero Extension
 Sign Extension
3 Engr.Sharif Kakar
Addressing Modes
4
 There are many ways in ARM to specify the address; these
are called addressing modes.
 Two modes associated with memory access instructions
are
1. Immediate offset addressing
2. Register offset addressing
The basic load and store instructions are:
 Load and Store Word or Byte or Half word
❖ LDR / STR / LDRB / STRB / LDRH / STRH
Engr.Sharif Kakar
Immediate Offset Addressing
 Base Register: Specify a register which contains the memory
address
❖ In case of the load instruction (LDR) this is the memory
address of the data that we want to retrieve from memory
❖ In case of the store instruction (STR), this is the memory
address where we want to write the value which is currently
in a register
 Example: [r0]
specifies the memory address pointed to by the value in r0
 The ARM data transfer instructions are all based around
register-indirect addressing, register being referenced is
called Base register
5 Engr.Sharif Kakar
Immediate Offset Addressing
6
 When the offset is an immediate value from the base
address stored in a register, the resulting addressing mode
is called immediate offset addressing.
 General syntax
 In immediate offset addressing mode contents of register
𝑅 𝑛 remain unchanged.
 Immediate value can be in between -255 to 255 in 16-bit
encoding or -4095 to 4095 in 32-bit encoding
Engr.Sharif Kakar
Data Types for LDR/STR Instruction
 Transfer data from memory to processor and vice versa,
The data item may be a byte, 16-bit half-word, a 32-bit
word
 Data types available and their range given in table 6.2
 When type field is not specified transfer of 32-bit take
place
7 Engr.Sharif Kakar
Illustration of LDR instruction Data Transfer
8
 LDR 𝑅0 , [𝑅1] ;
load R0 with data from memory pointed by 𝑅1
 Execution of the instruction LDR R0, [R1] will result in the
transfer of the 32-bit value pointed to by 𝑅1 in the destination
register 𝑅0.
 In 1st step LDR instruction is fetched from code memory
region addressed by PC
 This instruction is then decoded by the processor. After
decoding the instruction, the execution phase starts.
 The first sub-step in the execution phase is to use the
contents of register 𝑅1 as an address, which is sent on the
data bus address lines to read the contents from the data
memory shown as 3 in fig. 6.2
Engr.Sharif Kakar
LDR Instruction
9 Engr.Sharif Kakar
LDR Instruction
10
 4th step: For the LDR instruction, a read signal is sent on
the control bus to the data memory and as a result 32
bits are copied by the memory (from the corresponding
address) on the data lines of the data bus
 5th step: Finally, the data from the data bus is copied to
the register 𝑹𝟎 and this phase completes the execution
of the instruction. During the execution of this
instruction, the contents of register 𝑅1 are not changed
Engr.Sharif Kakar
Web link
 https://www.youtube.com/watch?v=07ATOG5wXPE
11 Engr.Sharif Kakar
Immediate Offset Addressing
12
 Immediate Addressing mode can be divided into
1. Pre-indexed immediate offset addressing
2. Post-indexed immediate offset addressing
 Pre-indexed immediate offset addressing: In pre-
indexed offset addressing the base address is updated first.
This updated address is used by STR/LDR instruction
during execution.
 General Syntax
Engr.Sharif Kakar
Pre-indexed immediate offset addressing:
13
 The presence of ‘!’ after the closing or right square
bracket ‘]’ indicates that the contents of the register
containing the base address are permanently updated and
distinguishes the pre-indexed addressing mode from the
immediate addressing mode.
Engr.Sharif Kakar
Post-index offset addressing
14
 If the base address contained in the address register is
updated after the load or store operation has been
performed, then this addressing mode is called the post-
index offset addressing mode.
 Example:
Engr.Sharif Kakar
Example 6.5
15
 (Copying single data at a time with post-indexing.).
Assume Src to be an array of numbers in the memory
section with READONLY attribute while Dst is an array
in the READWRITE memory section.We want to copy
the elements of Src to Dst using post-indexing.
Engr.Sharif Kakar
Register Offset Addressing
16
 In this addressing mode, the base address is contained in a
register while the offset value is also in a register.This is
unlike immediate offset addressing mode, where the
offset is an immediate value.
 Rn contains the base address to or from which an offset
contained in Rm is added or subtracted.The offset n is a
optional value and can be shifted by 0 to 3bits with left
shift logical operation.
Engr.Sharif Kakar
Aligned and unaligned memory access
17
 A 32-bit word object will result in an aligned word access
if the first two bits of its starting address are zero or if it
is divisible by 4. Otherwise, the 32-bit data access is
unaligned.
 Similarly, if the starting address of a 16-bit half word
object is divisible by 2 or its LSB is zero, we say the 16-bit
object is half-word aligned. Otherwise, its access will be
unaligned.
 Memory accesses of size 1 byte are, however always
aligned.
 Example 6.7 see exercise also
Engr.Sharif Kakar
6.6 Stack
18
 Covered on board, kindly see lecture notes
Engr.Sharif Kakar
6.2.4: Unprivileged Load and Store instructions
19
 Cortex-M processor can access the memory either in privileged
or unprivileged mode
 Load and store instructions with unprivileged access can be
used to mandate the applications running on top of the
operating system to have only unprivileged access thus allow a
restricted memory access to the application program.
 General Syntax:
 They perform same operation as LDR/STR with immediate
offset value but have unprivileged access
Engr.Sharif Kakar
Example
20 Engr.Sharif Kakar
LDR with PC- Relative Addressing Mode
21
 In PC-Relative addressing mode, memory address is
generated using an offset from current value of PC
 A label is used for representing an instruction address or
literal data in code memory region
 LDR {type}{cond} 𝑅𝑡, Label
 It is required that the label must be within an address
offset of ±4095 from the current instruction address.
Otherwise, the assembler generates an error
 The assembler may also permit us to directly write the
label as [PC, #number]. The expression [PC, #number]
generates the label address by adding or subtracting an
offset equal to #number to the current value of PC.
Engr.Sharif Kakar
Example
22 Engr.Sharif Kakar
ADR instruction
23
 ADR can be used to generate PC-relative addresses, it is
used to load addresses to registers
 General Syntax: ADR { cond } Rd, label
Here Rd is destination register, label is used for representing
an instruction address.
Example: ADR R2, TxtMsg
Engr.Sharif Kakar
Double and Multiple Word Memory Access
24
 In case memory data access becomes larger than word
then there are 2 solutions
1. One of them is to use the existing word size memory
access instruction repeatedly.
2. Cortex-M3 instruction allows either double or multiple
load and store operations to be performed in single
memory access instruction
 DoubleWord Memory Access
 General Syntax
Engr.Sharif Kakar
Example
25
 The first instruction in Example 6.18 loads register R1 with a
word at an address obtained by adding an offset of 32 bytes to
the value in register R2, and loads a word to R0 from an offset
of 36 bytes. The second instruction stores R3 to an address in
R7, and the register R4 to an address equal to R7 + 4 and then
decrements R7 by 16
Engr.Sharif Kakar
Multiple Word Load and Store Instructions
26
 Multiple registers can be loaded and stored using LDM (load
multiple) and STM (Store Multiple) instructions
 addrmode can be Increament After (IA) and Decreament
Before (DB), cond field is an optional field, 𝑹 𝒅 holds the base
memory address from which multiple registers are loaded and
stored.
 Reglist is the list of registers to be loaded or stored.
 {!} exclamation mark is an optional field and specifies whether
Rd should be updated after instruction execution or not.
Engr.Sharif Kakar
Multiple word load and Store instructions
27 Engr.Sharif Kakar
Multiple word Load and Store instructions
28
 In the above examples, R0 is the first register to be
copied to the memory, then R1 and in the end R3 is
stored in the memory.
 The LDM instructions work in the opposite manner as
compared to their STM counterparts.We may also
encounter instructions such as LDMFD and STMFD.The
LDM and LDMFD instructions are synonyms for LDMIA
while STMFD is a synonym for STMDB.
 For LDM, LDMIA, LDMFD, STM, and STMIA, the accesses
occur in order of increasing register numbers, with the
lowest numbered register using the lowest memory
address and the highest numbered register using the
highest memory address.
Engr.Sharif Kakar
Multiple Word Load and Store instruction
29
 For LDMDB, LDMEA, STMDB, and STMFD, the accesses
occur in order of decreasing register numbers, with the
highest numbered register using the highest memory
address and the lowest number register using the lowest
memory address.
 Assignment : example 6.21 + exercise problems for paper
Engr.Sharif Kakar

More Related Content

What's hot

8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay KumarVijay Kumar
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessorvenkateshkannat
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceAnurag Tomar
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Register of 80386
Register of 80386Register of 80386
Register of 80386aviban
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceChirag Parikh
 
Bus Interface Unit(BIU) of 8086 Microprocessor
Bus Interface Unit(BIU) of 8086 MicroprocessorBus Interface Unit(BIU) of 8086 Microprocessor
Bus Interface Unit(BIU) of 8086 MicroprocessorArafat Hossan
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolAditya Porwal
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
8086 MICROPROCESSOR
8086 MICROPROCESSOR8086 MICROPROCESSOR
8086 MICROPROCESSORAkhila Rahul
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignmentZia3130
 
EEPROM Part-21
EEPROM Part-21EEPROM Part-21
EEPROM Part-21Techvilla
 
I/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architectureI/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architecturekavitha muneeshwaran
 
Microprocessor 80386
Microprocessor 80386Microprocessor 80386
Microprocessor 80386yash sawarkar
 

What's hot (20)

8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar8051 microcontroller by K. Vijay Kumar
8051 microcontroller by K. Vijay Kumar
 
Introduction to 8085 microprocessor
Introduction to 8085 microprocessorIntroduction to 8085 microprocessor
Introduction to 8085 microprocessor
 
Micro programmed control
Micro programmed controlMicro programmed control
Micro programmed control
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
8086 architecture By Er. Swapnil Kaware
8086 architecture By Er. Swapnil Kaware8086 architecture By Er. Swapnil Kaware
8086 architecture By Er. Swapnil Kaware
 
DDR2 SDRAM
DDR2 SDRAMDDR2 SDRAM
DDR2 SDRAM
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Register of 80386
Register of 80386Register of 80386
Register of 80386
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Bus Interface Unit(BIU) of 8086 Microprocessor
Bus Interface Unit(BIU) of 8086 MicroprocessorBus Interface Unit(BIU) of 8086 Microprocessor
Bus Interface Unit(BIU) of 8086 Microprocessor
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
INSTRUCTION CYCLE
INSTRUCTION CYCLEINSTRUCTION CYCLE
INSTRUCTION CYCLE
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
ARM
ARMARM
ARM
 
8086 MICROPROCESSOR
8086 MICROPROCESSOR8086 MICROPROCESSOR
8086 MICROPROCESSOR
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignment
 
EEPROM Part-21
EEPROM Part-21EEPROM Part-21
EEPROM Part-21
 
Asic design
Asic designAsic design
Asic design
 
I/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architectureI/O system in intel 80386 microcomputer architecture
I/O system in intel 80386 microcomputer architecture
 
Microprocessor 80386
Microprocessor 80386Microprocessor 80386
Microprocessor 80386
 

Similar to Memory Access Instructions

Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction SetDr. Pankaj Zope
 
Module 2 instruction set
Module 2 instruction set Module 2 instruction set
Module 2 instruction set Deepak John
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modesbalbirvirdi
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction setStefan Oprea
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modessb108ec
 
microprocessor and microcontroller notes ppt
microprocessor and microcontroller notes pptmicroprocessor and microcontroller notes ppt
microprocessor and microcontroller notes pptmananjain543
 
Describe the three main addressing modes of the PIC16 architecture di.pdf
Describe the three main addressing modes of the PIC16 architecture di.pdfDescribe the three main addressing modes of the PIC16 architecture di.pdf
Describe the three main addressing modes of the PIC16 architecture di.pdfSALES97
 
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.pptManju Badiger
 
Addressing modes Breifly
Addressing modes BreiflyAddressing modes Breifly
Addressing modes BreiflyTahir Jalali
 
BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGNBASIC COMPUTER ORGANIZATION AND DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGNAnonymous Red
 
GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64Yi-Hsiu Hsu
 
instruction format and addressing modes
instruction format and addressing modesinstruction format and addressing modes
instruction format and addressing modesRamaPrabha24
 
micro chapter 3jjgffffyeyhhuyerfftfgggffgjj
micro chapter 3jjgffffyeyhhuyerfftfgggffgjjmicro chapter 3jjgffffyeyhhuyerfftfgggffgjj
micro chapter 3jjgffffyeyhhuyerfftfgggffgjjTadeseBeyene
 
Advanced computer architect lesson 3 and 4
Advanced computer architect lesson 3 and 4Advanced computer architect lesson 3 and 4
Advanced computer architect lesson 3 and 4Ismail Mukiibi
 
Comparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCComparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCApurv Nerlekar
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing ModesSenthil Kumar
 
Compreport
CompreportCompreport
Compreportxdarlord
 

Similar to Memory Access Instructions (20)

Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
Module 2 instruction set
Module 2 instruction set Module 2 instruction set
Module 2 instruction set
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modes
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
8051 addressing modes
8051 addressing modes8051 addressing modes
8051 addressing modes
 
Lecture9
Lecture9Lecture9
Lecture9
 
microprocessor and microcontroller notes ppt
microprocessor and microcontroller notes pptmicroprocessor and microcontroller notes ppt
microprocessor and microcontroller notes ppt
 
addressingmodes8051.ppt
addressingmodes8051.pptaddressingmodes8051.ppt
addressingmodes8051.ppt
 
Describe the three main addressing modes of the PIC16 architecture di.pdf
Describe the three main addressing modes of the PIC16 architecture di.pdfDescribe the three main addressing modes of the PIC16 architecture di.pdf
Describe the three main addressing modes of the PIC16 architecture di.pdf
 
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
 
Cao
CaoCao
Cao
 
Addressing modes Breifly
Addressing modes BreiflyAddressing modes Breifly
Addressing modes Breifly
 
BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGNBASIC COMPUTER ORGANIZATION AND DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGN
 
GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64GCC for ARMv8 Aarch64
GCC for ARMv8 Aarch64
 
instruction format and addressing modes
instruction format and addressing modesinstruction format and addressing modes
instruction format and addressing modes
 
micro chapter 3jjgffffyeyhhuyerfftfgggffgjj
micro chapter 3jjgffffyeyhhuyerfftfgggffgjjmicro chapter 3jjgffffyeyhhuyerfftfgggffgjj
micro chapter 3jjgffffyeyhhuyerfftfgggffgjj
 
Advanced computer architect lesson 3 and 4
Advanced computer architect lesson 3 and 4Advanced computer architect lesson 3 and 4
Advanced computer architect lesson 3 and 4
 
Comparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARCComparison between RISC architectures: MIPS, ARM and SPARC
Comparison between RISC architectures: MIPS, ARM and SPARC
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
Compreport
CompreportCompreport
Compreport
 

Recently uploaded

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
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
 
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 Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
★ 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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
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
 
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
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
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 Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
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
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

Memory Access Instructions

  • 1. Memory Access Instructions Chapter 6 1 Engr.Sharif Kakar
  • 2. Memory Access Instruction  Topics Covered:  ARM is a Load Store Architecture, all data processing instructions are executed in registers ❖ Does not support memory to memory data processing operations. ❖ Must move data values into registers before using them  LDR / Memory to register or LOAD from memory to register  STR / Register to memory or STORE from register to memory 3 sets of memory access instruction  Single register data transfer(LDR/STR)  Block data transfer(LDM/STM)  Single data swap (SWP) 2 Engr.Sharif Kakar
  • 3. Assembly Operands: Memory  Memory: Think of as single one-dimensional array where each cell stores a byte size value  Is referred to by a 32 bit address e.g. value at 0x4000 is 0x0a  Data is stored in memory as: variables, arrays, structures In LDR instruction we studied  Zero Extension  Sign Extension 3 Engr.Sharif Kakar
  • 4. Addressing Modes 4  There are many ways in ARM to specify the address; these are called addressing modes.  Two modes associated with memory access instructions are 1. Immediate offset addressing 2. Register offset addressing The basic load and store instructions are:  Load and Store Word or Byte or Half word ❖ LDR / STR / LDRB / STRB / LDRH / STRH Engr.Sharif Kakar
  • 5. Immediate Offset Addressing  Base Register: Specify a register which contains the memory address ❖ In case of the load instruction (LDR) this is the memory address of the data that we want to retrieve from memory ❖ In case of the store instruction (STR), this is the memory address where we want to write the value which is currently in a register  Example: [r0] specifies the memory address pointed to by the value in r0  The ARM data transfer instructions are all based around register-indirect addressing, register being referenced is called Base register 5 Engr.Sharif Kakar
  • 6. Immediate Offset Addressing 6  When the offset is an immediate value from the base address stored in a register, the resulting addressing mode is called immediate offset addressing.  General syntax  In immediate offset addressing mode contents of register 𝑅 𝑛 remain unchanged.  Immediate value can be in between -255 to 255 in 16-bit encoding or -4095 to 4095 in 32-bit encoding Engr.Sharif Kakar
  • 7. Data Types for LDR/STR Instruction  Transfer data from memory to processor and vice versa, The data item may be a byte, 16-bit half-word, a 32-bit word  Data types available and their range given in table 6.2  When type field is not specified transfer of 32-bit take place 7 Engr.Sharif Kakar
  • 8. Illustration of LDR instruction Data Transfer 8  LDR 𝑅0 , [𝑅1] ; load R0 with data from memory pointed by 𝑅1  Execution of the instruction LDR R0, [R1] will result in the transfer of the 32-bit value pointed to by 𝑅1 in the destination register 𝑅0.  In 1st step LDR instruction is fetched from code memory region addressed by PC  This instruction is then decoded by the processor. After decoding the instruction, the execution phase starts.  The first sub-step in the execution phase is to use the contents of register 𝑅1 as an address, which is sent on the data bus address lines to read the contents from the data memory shown as 3 in fig. 6.2 Engr.Sharif Kakar
  • 10. LDR Instruction 10  4th step: For the LDR instruction, a read signal is sent on the control bus to the data memory and as a result 32 bits are copied by the memory (from the corresponding address) on the data lines of the data bus  5th step: Finally, the data from the data bus is copied to the register 𝑹𝟎 and this phase completes the execution of the instruction. During the execution of this instruction, the contents of register 𝑅1 are not changed Engr.Sharif Kakar
  • 12. Immediate Offset Addressing 12  Immediate Addressing mode can be divided into 1. Pre-indexed immediate offset addressing 2. Post-indexed immediate offset addressing  Pre-indexed immediate offset addressing: In pre- indexed offset addressing the base address is updated first. This updated address is used by STR/LDR instruction during execution.  General Syntax Engr.Sharif Kakar
  • 13. Pre-indexed immediate offset addressing: 13  The presence of ‘!’ after the closing or right square bracket ‘]’ indicates that the contents of the register containing the base address are permanently updated and distinguishes the pre-indexed addressing mode from the immediate addressing mode. Engr.Sharif Kakar
  • 14. Post-index offset addressing 14  If the base address contained in the address register is updated after the load or store operation has been performed, then this addressing mode is called the post- index offset addressing mode.  Example: Engr.Sharif Kakar
  • 15. Example 6.5 15  (Copying single data at a time with post-indexing.). Assume Src to be an array of numbers in the memory section with READONLY attribute while Dst is an array in the READWRITE memory section.We want to copy the elements of Src to Dst using post-indexing. Engr.Sharif Kakar
  • 16. Register Offset Addressing 16  In this addressing mode, the base address is contained in a register while the offset value is also in a register.This is unlike immediate offset addressing mode, where the offset is an immediate value.  Rn contains the base address to or from which an offset contained in Rm is added or subtracted.The offset n is a optional value and can be shifted by 0 to 3bits with left shift logical operation. Engr.Sharif Kakar
  • 17. Aligned and unaligned memory access 17  A 32-bit word object will result in an aligned word access if the first two bits of its starting address are zero or if it is divisible by 4. Otherwise, the 32-bit data access is unaligned.  Similarly, if the starting address of a 16-bit half word object is divisible by 2 or its LSB is zero, we say the 16-bit object is half-word aligned. Otherwise, its access will be unaligned.  Memory accesses of size 1 byte are, however always aligned.  Example 6.7 see exercise also Engr.Sharif Kakar
  • 18. 6.6 Stack 18  Covered on board, kindly see lecture notes Engr.Sharif Kakar
  • 19. 6.2.4: Unprivileged Load and Store instructions 19  Cortex-M processor can access the memory either in privileged or unprivileged mode  Load and store instructions with unprivileged access can be used to mandate the applications running on top of the operating system to have only unprivileged access thus allow a restricted memory access to the application program.  General Syntax:  They perform same operation as LDR/STR with immediate offset value but have unprivileged access Engr.Sharif Kakar
  • 21. LDR with PC- Relative Addressing Mode 21  In PC-Relative addressing mode, memory address is generated using an offset from current value of PC  A label is used for representing an instruction address or literal data in code memory region  LDR {type}{cond} 𝑅𝑡, Label  It is required that the label must be within an address offset of ±4095 from the current instruction address. Otherwise, the assembler generates an error  The assembler may also permit us to directly write the label as [PC, #number]. The expression [PC, #number] generates the label address by adding or subtracting an offset equal to #number to the current value of PC. Engr.Sharif Kakar
  • 23. ADR instruction 23  ADR can be used to generate PC-relative addresses, it is used to load addresses to registers  General Syntax: ADR { cond } Rd, label Here Rd is destination register, label is used for representing an instruction address. Example: ADR R2, TxtMsg Engr.Sharif Kakar
  • 24. Double and Multiple Word Memory Access 24  In case memory data access becomes larger than word then there are 2 solutions 1. One of them is to use the existing word size memory access instruction repeatedly. 2. Cortex-M3 instruction allows either double or multiple load and store operations to be performed in single memory access instruction  DoubleWord Memory Access  General Syntax Engr.Sharif Kakar
  • 25. Example 25  The first instruction in Example 6.18 loads register R1 with a word at an address obtained by adding an offset of 32 bytes to the value in register R2, and loads a word to R0 from an offset of 36 bytes. The second instruction stores R3 to an address in R7, and the register R4 to an address equal to R7 + 4 and then decrements R7 by 16 Engr.Sharif Kakar
  • 26. Multiple Word Load and Store Instructions 26  Multiple registers can be loaded and stored using LDM (load multiple) and STM (Store Multiple) instructions  addrmode can be Increament After (IA) and Decreament Before (DB), cond field is an optional field, 𝑹 𝒅 holds the base memory address from which multiple registers are loaded and stored.  Reglist is the list of registers to be loaded or stored.  {!} exclamation mark is an optional field and specifies whether Rd should be updated after instruction execution or not. Engr.Sharif Kakar
  • 27. Multiple word load and Store instructions 27 Engr.Sharif Kakar
  • 28. Multiple word Load and Store instructions 28  In the above examples, R0 is the first register to be copied to the memory, then R1 and in the end R3 is stored in the memory.  The LDM instructions work in the opposite manner as compared to their STM counterparts.We may also encounter instructions such as LDMFD and STMFD.The LDM and LDMFD instructions are synonyms for LDMIA while STMFD is a synonym for STMDB.  For LDM, LDMIA, LDMFD, STM, and STMIA, the accesses occur in order of increasing register numbers, with the lowest numbered register using the lowest memory address and the highest numbered register using the highest memory address. Engr.Sharif Kakar
  • 29. Multiple Word Load and Store instruction 29  For LDMDB, LDMEA, STMDB, and STMFD, the accesses occur in order of decreasing register numbers, with the highest numbered register using the highest memory address and the lowest number register using the lowest memory address.  Assignment : example 6.21 + exercise problems for paper Engr.Sharif Kakar