SlideShare a Scribd company logo
1 of 35
Module : Embedded & Real Time System.
Lecture : 7
UNIT2: Instruction Sets
Topics Covered :ARM
Lecture by :P. Jenifer Darling Rosita,
ARM INSTRUCTION SET
• ARM VERSIONS.
• ARM ASSEMBLY LANGUAGE.
• ARM PROGRAMMING MODEL.
• ARM MEMORY ORGANIZATION.
• ARM DATA OPERATIONS.
• ARM FLOW OF CONTROL.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM VERSIONS
• ARM ARCHITECTURE HAS BEEN EXTENDED OVER
SEVERAL VERSIONS.
• WE WILL CONCENTRATE ON ARM7.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM ASSEMBLY LANGUAGE
• FAIRLY STANDARD ASSEMBLY LANGUAGE:
LDR R0,[R8] ; A COMMENT
LABEL ADD R4,R0,R1
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
© 2000 Morgan KaufmanOverheads for Computers as Components
• ARM is a load-store architecture
 data operands must first be loaded into the CPU and
then stored back to main memory to save the results. 
• ARM has 16 general-purpose registers, r0 through r15.
• Except for r15, they are identical
 any operation that can be done on one of them can be
done on the others.
 The r15 register has the same capabilities as the other
registers, but it is also used as the program counter.
Program Counter:
It store the address of next instruction to be
ARM PROGRAMMING MODEL
ARM PROGRAMMING MODEL
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r13
r14
r15 (PC)
CPSR
31 0
N Z C V
 Current program status register (CPSR).
•This register is set automatically during every arithmetic,
logical, or shifting operation.
•The top four bits of the CPSR hold the following useful
information about the results of that arithmetic/-logical
operation:
© 2000 Morgan KaufmanOverheads for Computers as Components
• The negative (N) bit is set when the result is negative
in two’s-complement arithmetic.
• The zero (Z) bit is set when every bit of the result is
zero.
• The carry (C) bit is set when there is a carry out of the
operation.
• The overflow (V) bit is set when an arithmetic
operation results in an overflow.
These bits can be used to easily check the results of an
arithmetic operation.
Example 2.1 Status Bit Computation in the ARM
An ARM word is 32 bits. In C notation, a hexadecimal
number starts with 0x, such as 0xffffffff, which is a two’s-
complement representation of −1 in a 32-bit word.
Here are some sample calculations:
• −1  + 1  = 0 : Written in 32-bit format, this becomes 0xffffffff
+ 0x1 = 0x0, giving the CPSR value of NZCV = 1001.
• 0 1 = 1 :− −  0x0 − 0x1 = 0xffffffff, with NZCV = 1000.
• 231
1 + 1 = 2− − 31
:  0x7fffffff + 0x1 = 0x80000000, with
NZCV = 0101.
ARM DATA INSTRUCTIONS
• BASIC FORMAT:
ADD R0,R1,R2
• COMPUTES R1+R2, STORES IN R0.
• IMMEDIATE OPERAND:
ADD R0,R1,#2
• COMPUTES R1+2, STORES IN R0.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ENDIANNESS
• RELATIONSHIP BETWEEN BIT AND BYTE/WORD ORDERING
DEFINES ENDIANNESS:
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
byte 3 byte 2 byte 1 byte 0 byte 0 byte 1 byte 2 byte 3
bit 31 bit 0 bit 0 bit 31
little-endian big-endian
ARM DATA TYPES
• WORD IS 32 BITS LONG.
• WORD CAN BE DIVIDED INTO FOUR 8-BIT BYTES.
• ARM ADDRESSES CAM BE 32 BITS LONG.
• ADDRESS REFERS TO BYTE.
• ADDRESS 4 STARTS AT BYTE 4.
• CAN BE CONFIGURED AT POWER-UP AS EITHER LITTLE-
OR BIT-ENDIAN MODE.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM DATA INSTRUCTIONS
• ADD, ADC : ADD (W.
CARRY)
• SUB, SBC : SUBTRACT (W.
CARRY)
• RSB, RSC : REVERSE
SUBTRACT (W. CARRY)
• MUL, MLA : MULTIPLY (AND
ACCUMULATE)
• AND, ORR, EOR
• BIC : BIT CLEAR
• LSL, LSR : LOGICAL SHIFT
LEFT/RIGHT
• ASL, ASR : ARITHMETIC
SHIFT LEFT/RIGHT
• ROR : ROTATE RIGHT
• RRX : ROTATE RIGHT
EXTENDED WITH C
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM MOVE INSTRUCTIONS
• MOV, MVN : MOVE (NEGATED)
MOV R0, R1 ; SETS R0 TO R1
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM LOAD/STORE
INSTRUCTIONS
• LDR, LDRH, LDRB : LOAD (HALF-WORD, BYTE)
• STR, STRH, STRB : STORE (HALF-WORD, BYTE)
• ADDRESSING MODES:
• REGISTER INDIRECT : LDR R0,[R1]
• WITH SECOND REGISTER : LDR R0,[R1,-R2]
• WITH CONSTANT : LDR R0,[R1,#4]
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM ADR PSEUDO-OP
• CANNOT REFER TO AN ADDRESS DIRECTLY IN AN
INSTRUCTION.
• GENERATE VALUE BY PERFORMING ARITHMETIC ON PC.
• ADR PSEUDO-OP GENERATES INSTRUCTION REQUIRED
TO CALCULATE ADDRESS:
ADR R1,FOO
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: C ASSIGNMENTS
• C:
X = (A + B) - C;
• ASSEMBLER:
ADR R4,A ; GET ADDRESS FOR A
LDR R0,[R4] ; GET VALUE OF A
ADR R4,B ; GET ADDRESS FOR B, REUSING R4
LDR R1,[R4] ; GET VALUE OF B
ADD R3,R0,R1 ; COMPUTE A+B
ADR R4,C ; GET ADDRESS FOR C
LDR R2[R4] ; GET VALUE OF C
vOverheads for Computers as Components 2nd
ed.
C ASSIGNMENT, CONT’D.
SUB R3,R3,R2 ; COMPLETE COMPUTATION OF X
ADR R4,X ; GET ADDRESS FOR X
STR R3[R4] ; STORE VALUE OF X
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: C ASSIGNMENT
• C:
Y = A*(B+C);
• ASSEMBLER:
ADR R4,B ; GET ADDRESS FOR B
LDR R0,[R4] ; GET VALUE OF B
ADR R4,C ; GET ADDRESS FOR C
LDR R1,[R4] ; GET VALUE OF C
ADD R2,R0,R1 ; COMPUTE PARTIAL RESULT
ADR R4,A ; GET ADDRESS FOR A
LDR R0,[R4] ; GET VALUE OF A
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
C ASSIGNMENT, CONT’D.
MUL R2,R2,R0 ; COMPUTE FINAL VALUE FOR Y
ADR R4,Y ; GET ADDRESS FOR Y
STR R2,[R4] ; STORE Y
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: C ASSIGNMENT
• C:
Z = (A << 2) | (B & 15);
• ASSEMBLER:
ADR R4,A ; GET ADDRESS FOR A
LDR R0,[R4] ; GET VALUE OF A
MOV R0,R0,LSL 2 ; PERFORM SHIFT
ADR R4,B ; GET ADDRESS FOR B
LDR R1,[R4] ; GET VALUE OF B
AND R1,R1,#15 ; PERFORM AND
ORR R1,R0,R1 ; PERFORM OR
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
C ASSIGNMENT, CONT’D.
ADR R4,Z ; GET ADDRESS FOR Z
STR R1,[R4] ; STORE VALUE FOR Z
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ADDITIONAL ADDRESSING
MODES
• BASE-PLUS-OFFSET ADDRESSING:
LDR R0,[R1,#16]
• LOADS FROM LOCATION R1+16
• AUTO-INDEXING INCREMENTS BASE REGISTER:
LDR R0,[R1,#16]!
• POST-INDEXING FETCHES, THEN DOES OFFSET:
LDR R0,[R1],#16
• LOADS R0 FROM R1, THEN ADDS 16 TO R1.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM FLOW OF CONTROL
• ALL OPERATIONS CAN BE PERFORMED CONDITIONALLY,
TESTING CPSR:
• EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE
• BRANCH OPERATION:
B #100
• CAN BE PERFORMED CONDITIONALLY.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: IF STATEMENT
• C:
IF (A > B) { X = 5; Y = C + D; } ELSE X = C - D;
• ASSEMBLER:
; COMPUTE AND TEST CONDITION
ADR R4,A ; GET ADDRESS FOR A
LDR R0,[R4] ; GET VALUE OF A
ADR R4,B ; GET ADDRESS FOR B
LDR R1,[R4] ; GET VALUE FOR B
CMP R0,R1 ; COMPARE A < B
BGE FBLOCK ; IF A >= B, BRANCH TO FALSE BLOCK
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
IF STATEMENT, CONT’D.
; TRUE BLOCK
MOV R0,#5 ; GENERATE VALUE FOR X
ADR R4,X ; GET ADDRESS FOR X
STR R0,[R4] ; STORE X
ADR R4,C ; GET ADDRESS FOR C
LDR R0,[R4] ; GET VALUE OF C
ADR R4,D ; GET ADDRESS FOR D
LDR R1,[R4] ; GET VALUE OF D
ADD R0,R0,R1 ; COMPUTE Y
ADR R4,Y ; GET ADDRESS FOR Y
STR R0,[R4] ; STORE Y
B AFTER ; BRANCH AROUND FALSE BLOCK
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
IF STATEMENT, CONT’D.
; FALSE BLOCK
FBLOCK ADR R4,C ; GET ADDRESS FOR C
LDR R0,[R4] ; GET VALUE OF C
ADR R4,D ; GET ADDRESS FOR D
LDR R1,[R4] ; GET VALUE FOR D
SUB R0,R0,R1 ; COMPUTE A-B
ADR R4,X ; GET ADDRESS FOR X
STR R0,[R4] ; STORE VALUE OF X
AFTER ...
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: CONDITIONAL
INSTRUCTION IMPLEMENTATION
; TRUE BLOCK
MOVLT R0,#5 ; GENERATE VALUE FOR X
ADRLT R4,X ; GET ADDRESS FOR X
STRLT R0,[R4] ; STORE X
ADRLT R4,C ; GET ADDRESS FOR C
LDRLT R0,[R4] ; GET VALUE OF C
ADRLT R4,D ; GET ADDRESS FOR D
LDRLT R1,[R4] ; GET VALUE OF D
ADDLT R0,R0,R1 ; COMPUTE Y
ADRLT R4,Y ; GET ADDRESS FOR Y
STRLT R0,[R4] ; STORE Y
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: SWITCH STATEMENT
• C:
SWITCH (TEST) { CASE 0: … BREAK; CASE 1: … }
• ASSEMBLER:
ADR R2,TEST ; GET ADDRESS FOR TEST
LDR R0,[R2] ; LOAD VALUE FOR TEST
ADR R1,SWITCHTAB ; LOAD ADDRESS FOR SWITCH TABLE
LDR R1,[R1,R0,LSL #2] ; INDEX SWITCH TABLE
SWITCHTAB DCD CASE0
DCD CASE1
...
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
EXAMPLE: FIR FILTER
• C:
FOR (I=0, F=0; I<N; I++)
F = F + C[I]*X[I];
• ASSEMBLER
; LOOP INITIATION CODE
MOV R0,#0 ; USE R0 FOR I
MOV R8,#0 ; USE SEPARATE INDEX FOR ARRAYS
ADR R2,N ; GET ADDRESS FOR N
LDR R1,[R2] ; GET VALUE OF N
MOV R2,#0 ; USE R2 FOR F
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
FIR FILTER, CONT’.D
ADR R3,C ; LOAD R3 WITH BASE OF C
ADR R5,X ; LOAD R5 WITH BASE OF X
; LOOP BODY
LOOP LDR R4,[R3,R8] ; GET C[I]
LDR R6,[R5,R8] ; GET X[I]
MUL R4,R4,R6 ; COMPUTE C[I]*X[I]
ADD R2,R2,R4 ; ADD INTO RUNNING SUM
ADD R8,R8,#4 ; ADD ONE WORD OFFSET TO ARRAY INDEX
ADD R0,R0,#1 ; ADD 1 TO I
CMP R0,R1 ; EXIT?
BLT LOOP ; IF I < N, CONTINUE
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
ARM SUBROUTINE LINKAGE
• BRANCH AND LINK INSTRUCTION:
BL FOO
• COPIES CURRENT PC TO R14.
• TO RETURN FROM SUBROUTINE:
MOV R15,R14
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
NESTED SUBROUTINE CALLS
• NESTING/RECURSION REQUIRES CODING CONVENTION:
F1 LDR R0,[R13] ; LOAD ARG INTO R0 FROM STACK
; CALL F2()
STR R13!,[R14] ; STORE F1’S RETURN ADRS
STR R13!,[R0] ; STORE ARG TO F2 ON STACK
BL F2 ; BRANCH AND LINK TO F2
; RETURN FROM F1()
SUB R13,#4 ; POP F2’S ARG OFF STACK
LDR R13!,R15 ; RESTORE REGISTER AND RETURN
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.
SUMMARY
• LOAD/STORE ARCHITECTURE
• MOST INSTRUCTIONS ARE RISCY, OPERATE IN SINGLE
CYCLE.
• SOME MULTI-REGISTER OPERATIONS TAKE LONGER.
• ALL INSTRUCTIONS CAN BE EXECUTED CONDITIONALLY.
© 2008 Wayne WolfOverheads for Computers as Components 2nd
ed.

More Related Content

What's hot

Microcontroller instruction set
Microcontroller instruction setMicrocontroller instruction set
Microcontroller instruction setShail Modi
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching materialJohn Williams
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent vijaydeepakg
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction SetDwight Sabio
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051techbed
 
FM TwoO & CRC FM-RDS Android Library
FM TwoO & CRC FM-RDS Android LibraryFM TwoO & CRC FM-RDS Android Library
FM TwoO & CRC FM-RDS Android LibraryRoy Kyrillos
 
Section 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setSection 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setnueng-kk
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction setjustus_pm
 
Etl andrew bond_sspi_maio_2015
Etl andrew bond_sspi_maio_2015Etl andrew bond_sspi_maio_2015
Etl andrew bond_sspi_maio_2015SSPI Brasil
 
CRC FM TwoO presented to NRSC
CRC FM TwoO presented to NRSCCRC FM TwoO presented to NRSC
CRC FM TwoO presented to NRSCFrancois Lefebvre
 

What's hot (20)

Microcontroller instruction set
Microcontroller instruction setMicrocontroller instruction set
Microcontroller instruction set
 
ARM lab programs
ARM  lab programs  ARM  lab programs
ARM lab programs
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction Set
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 
FM-RDS developments at CRC
FM-RDS developments at CRCFM-RDS developments at CRC
FM-RDS developments at CRC
 
8255 programming
8255 programming8255 programming
8255 programming
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051
 
FM TwoO & CRC FM-RDS Android Library
FM TwoO & CRC FM-RDS Android LibraryFM TwoO & CRC FM-RDS Android Library
FM TwoO & CRC FM-RDS Android Library
 
Section 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction setSection 1 8051 microcontroller instruction set
Section 1 8051 microcontroller instruction set
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
Etl andrew bond_sspi_maio_2015
Etl andrew bond_sspi_maio_2015Etl andrew bond_sspi_maio_2015
Etl andrew bond_sspi_maio_2015
 
CRC FM TwoO presented to NRSC
CRC FM TwoO presented to NRSCCRC FM TwoO presented to NRSC
CRC FM TwoO presented to NRSC
 

Similar to ARM Instruction Set & Assembly Code

Similar to ARM Instruction Set & Assembly Code (20)

ch2-arm-1.ppt
ch2-arm-1.pptch2-arm-1.ppt
ch2-arm-1.ppt
 
S emb t4-arch_cpu
S emb t4-arch_cpuS emb t4-arch_cpu
S emb t4-arch_cpu
 
Module 2 PPT of ES.pptx
Module 2 PPT of ES.pptxModule 2 PPT of ES.pptx
Module 2 PPT of ES.pptx
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Controlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault InjectionControlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault Injection
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.ppt
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systems
 
OptimizingARM
OptimizingARMOptimizingARM
OptimizingARM
 
Introduction to computer architecture .pptx
Introduction to computer architecture .pptxIntroduction to computer architecture .pptx
Introduction to computer architecture .pptx
 
Unit vi
Unit viUnit vi
Unit vi
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
 
arm.pptx
arm.pptxarm.pptx
arm.pptx
 
swrp141.pdf
swrp141.pdfswrp141.pdf
swrp141.pdf
 
Chapter3 presentation2
Chapter3 presentation2Chapter3 presentation2
Chapter3 presentation2
 
8255
82558255
8255
 
ARMbuilt-inshift_2a6f2cdd75038e8c46c6d481aac833ec.pdf
ARMbuilt-inshift_2a6f2cdd75038e8c46c6d481aac833ec.pdfARMbuilt-inshift_2a6f2cdd75038e8c46c6d481aac833ec.pdf
ARMbuilt-inshift_2a6f2cdd75038e8c46c6d481aac833ec.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
 
Code generation
Code generationCode generation
Code generation
 
Microprocessors and microcontrollers
Microprocessors and microcontrollers Microprocessors and microcontrollers
Microprocessors and microcontrollers
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

ARM Instruction Set & Assembly Code

  • 1. Module : Embedded & Real Time System. Lecture : 7 UNIT2: Instruction Sets Topics Covered :ARM Lecture by :P. Jenifer Darling Rosita,
  • 2. ARM INSTRUCTION SET • ARM VERSIONS. • ARM ASSEMBLY LANGUAGE. • ARM PROGRAMMING MODEL. • ARM MEMORY ORGANIZATION. • ARM DATA OPERATIONS. • ARM FLOW OF CONTROL. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 3. ARM VERSIONS • ARM ARCHITECTURE HAS BEEN EXTENDED OVER SEVERAL VERSIONS. • WE WILL CONCENTRATE ON ARM7. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 4. ARM ASSEMBLY LANGUAGE • FAIRLY STANDARD ASSEMBLY LANGUAGE: LDR R0,[R8] ; A COMMENT LABEL ADD R4,R0,R1 © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 5. © 2000 Morgan KaufmanOverheads for Computers as Components • ARM is a load-store architecture  data operands must first be loaded into the CPU and then stored back to main memory to save the results.  • ARM has 16 general-purpose registers, r0 through r15. • Except for r15, they are identical  any operation that can be done on one of them can be done on the others.  The r15 register has the same capabilities as the other registers, but it is also used as the program counter. Program Counter: It store the address of next instruction to be ARM PROGRAMMING MODEL
  • 6. ARM PROGRAMMING MODEL © 2008 Wayne WolfOverheads for Computers as Components 2nd ed. r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 (PC) CPSR 31 0 N Z C V
  • 7.  Current program status register (CPSR). •This register is set automatically during every arithmetic, logical, or shifting operation. •The top four bits of the CPSR hold the following useful information about the results of that arithmetic/-logical operation:
  • 8. © 2000 Morgan KaufmanOverheads for Computers as Components • The negative (N) bit is set when the result is negative in two’s-complement arithmetic. • The zero (Z) bit is set when every bit of the result is zero. • The carry (C) bit is set when there is a carry out of the operation. • The overflow (V) bit is set when an arithmetic operation results in an overflow. These bits can be used to easily check the results of an arithmetic operation.
  • 9. Example 2.1 Status Bit Computation in the ARM An ARM word is 32 bits. In C notation, a hexadecimal number starts with 0x, such as 0xffffffff, which is a two’s- complement representation of −1 in a 32-bit word. Here are some sample calculations: • −1  + 1  = 0 : Written in 32-bit format, this becomes 0xffffffff + 0x1 = 0x0, giving the CPSR value of NZCV = 1001. • 0 1 = 1 :− −  0x0 − 0x1 = 0xffffffff, with NZCV = 1000. • 231 1 + 1 = 2− − 31 :  0x7fffffff + 0x1 = 0x80000000, with NZCV = 0101.
  • 10. ARM DATA INSTRUCTIONS • BASIC FORMAT: ADD R0,R1,R2 • COMPUTES R1+R2, STORES IN R0. • IMMEDIATE OPERAND: ADD R0,R1,#2 • COMPUTES R1+2, STORES IN R0. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 11.
  • 12. ENDIANNESS • RELATIONSHIP BETWEEN BIT AND BYTE/WORD ORDERING DEFINES ENDIANNESS: © 2008 Wayne WolfOverheads for Computers as Components 2nd ed. byte 3 byte 2 byte 1 byte 0 byte 0 byte 1 byte 2 byte 3 bit 31 bit 0 bit 0 bit 31 little-endian big-endian
  • 13. ARM DATA TYPES • WORD IS 32 BITS LONG. • WORD CAN BE DIVIDED INTO FOUR 8-BIT BYTES. • ARM ADDRESSES CAM BE 32 BITS LONG. • ADDRESS REFERS TO BYTE. • ADDRESS 4 STARTS AT BYTE 4. • CAN BE CONFIGURED AT POWER-UP AS EITHER LITTLE- OR BIT-ENDIAN MODE. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 14. ARM DATA INSTRUCTIONS • ADD, ADC : ADD (W. CARRY) • SUB, SBC : SUBTRACT (W. CARRY) • RSB, RSC : REVERSE SUBTRACT (W. CARRY) • MUL, MLA : MULTIPLY (AND ACCUMULATE) • AND, ORR, EOR • BIC : BIT CLEAR • LSL, LSR : LOGICAL SHIFT LEFT/RIGHT • ASL, ASR : ARITHMETIC SHIFT LEFT/RIGHT • ROR : ROTATE RIGHT • RRX : ROTATE RIGHT EXTENDED WITH C © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 15. ARM MOVE INSTRUCTIONS • MOV, MVN : MOVE (NEGATED) MOV R0, R1 ; SETS R0 TO R1 © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 16. ARM LOAD/STORE INSTRUCTIONS • LDR, LDRH, LDRB : LOAD (HALF-WORD, BYTE) • STR, STRH, STRB : STORE (HALF-WORD, BYTE) • ADDRESSING MODES: • REGISTER INDIRECT : LDR R0,[R1] • WITH SECOND REGISTER : LDR R0,[R1,-R2] • WITH CONSTANT : LDR R0,[R1,#4] © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 17. ARM ADR PSEUDO-OP • CANNOT REFER TO AN ADDRESS DIRECTLY IN AN INSTRUCTION. • GENERATE VALUE BY PERFORMING ARITHMETIC ON PC. • ADR PSEUDO-OP GENERATES INSTRUCTION REQUIRED TO CALCULATE ADDRESS: ADR R1,FOO © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 18. EXAMPLE: C ASSIGNMENTS • C: X = (A + B) - C; • ASSEMBLER: ADR R4,A ; GET ADDRESS FOR A LDR R0,[R4] ; GET VALUE OF A ADR R4,B ; GET ADDRESS FOR B, REUSING R4 LDR R1,[R4] ; GET VALUE OF B ADD R3,R0,R1 ; COMPUTE A+B ADR R4,C ; GET ADDRESS FOR C LDR R2[R4] ; GET VALUE OF C vOverheads for Computers as Components 2nd ed.
  • 19. C ASSIGNMENT, CONT’D. SUB R3,R3,R2 ; COMPLETE COMPUTATION OF X ADR R4,X ; GET ADDRESS FOR X STR R3[R4] ; STORE VALUE OF X © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 20. EXAMPLE: C ASSIGNMENT • C: Y = A*(B+C); • ASSEMBLER: ADR R4,B ; GET ADDRESS FOR B LDR R0,[R4] ; GET VALUE OF B ADR R4,C ; GET ADDRESS FOR C LDR R1,[R4] ; GET VALUE OF C ADD R2,R0,R1 ; COMPUTE PARTIAL RESULT ADR R4,A ; GET ADDRESS FOR A LDR R0,[R4] ; GET VALUE OF A © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 21. C ASSIGNMENT, CONT’D. MUL R2,R2,R0 ; COMPUTE FINAL VALUE FOR Y ADR R4,Y ; GET ADDRESS FOR Y STR R2,[R4] ; STORE Y © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 22. EXAMPLE: C ASSIGNMENT • C: Z = (A << 2) | (B & 15); • ASSEMBLER: ADR R4,A ; GET ADDRESS FOR A LDR R0,[R4] ; GET VALUE OF A MOV R0,R0,LSL 2 ; PERFORM SHIFT ADR R4,B ; GET ADDRESS FOR B LDR R1,[R4] ; GET VALUE OF B AND R1,R1,#15 ; PERFORM AND ORR R1,R0,R1 ; PERFORM OR © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 23. C ASSIGNMENT, CONT’D. ADR R4,Z ; GET ADDRESS FOR Z STR R1,[R4] ; STORE VALUE FOR Z © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 24. ADDITIONAL ADDRESSING MODES • BASE-PLUS-OFFSET ADDRESSING: LDR R0,[R1,#16] • LOADS FROM LOCATION R1+16 • AUTO-INDEXING INCREMENTS BASE REGISTER: LDR R0,[R1,#16]! • POST-INDEXING FETCHES, THEN DOES OFFSET: LDR R0,[R1],#16 • LOADS R0 FROM R1, THEN ADDS 16 TO R1. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 25. ARM FLOW OF CONTROL • ALL OPERATIONS CAN BE PERFORMED CONDITIONALLY, TESTING CPSR: • EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE • BRANCH OPERATION: B #100 • CAN BE PERFORMED CONDITIONALLY. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 26. EXAMPLE: IF STATEMENT • C: IF (A > B) { X = 5; Y = C + D; } ELSE X = C - D; • ASSEMBLER: ; COMPUTE AND TEST CONDITION ADR R4,A ; GET ADDRESS FOR A LDR R0,[R4] ; GET VALUE OF A ADR R4,B ; GET ADDRESS FOR B LDR R1,[R4] ; GET VALUE FOR B CMP R0,R1 ; COMPARE A < B BGE FBLOCK ; IF A >= B, BRANCH TO FALSE BLOCK © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 27. IF STATEMENT, CONT’D. ; TRUE BLOCK MOV R0,#5 ; GENERATE VALUE FOR X ADR R4,X ; GET ADDRESS FOR X STR R0,[R4] ; STORE X ADR R4,C ; GET ADDRESS FOR C LDR R0,[R4] ; GET VALUE OF C ADR R4,D ; GET ADDRESS FOR D LDR R1,[R4] ; GET VALUE OF D ADD R0,R0,R1 ; COMPUTE Y ADR R4,Y ; GET ADDRESS FOR Y STR R0,[R4] ; STORE Y B AFTER ; BRANCH AROUND FALSE BLOCK © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 28. IF STATEMENT, CONT’D. ; FALSE BLOCK FBLOCK ADR R4,C ; GET ADDRESS FOR C LDR R0,[R4] ; GET VALUE OF C ADR R4,D ; GET ADDRESS FOR D LDR R1,[R4] ; GET VALUE FOR D SUB R0,R0,R1 ; COMPUTE A-B ADR R4,X ; GET ADDRESS FOR X STR R0,[R4] ; STORE VALUE OF X AFTER ... © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 29. EXAMPLE: CONDITIONAL INSTRUCTION IMPLEMENTATION ; TRUE BLOCK MOVLT R0,#5 ; GENERATE VALUE FOR X ADRLT R4,X ; GET ADDRESS FOR X STRLT R0,[R4] ; STORE X ADRLT R4,C ; GET ADDRESS FOR C LDRLT R0,[R4] ; GET VALUE OF C ADRLT R4,D ; GET ADDRESS FOR D LDRLT R1,[R4] ; GET VALUE OF D ADDLT R0,R0,R1 ; COMPUTE Y ADRLT R4,Y ; GET ADDRESS FOR Y STRLT R0,[R4] ; STORE Y © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 30. EXAMPLE: SWITCH STATEMENT • C: SWITCH (TEST) { CASE 0: … BREAK; CASE 1: … } • ASSEMBLER: ADR R2,TEST ; GET ADDRESS FOR TEST LDR R0,[R2] ; LOAD VALUE FOR TEST ADR R1,SWITCHTAB ; LOAD ADDRESS FOR SWITCH TABLE LDR R1,[R1,R0,LSL #2] ; INDEX SWITCH TABLE SWITCHTAB DCD CASE0 DCD CASE1 ... © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 31. EXAMPLE: FIR FILTER • C: FOR (I=0, F=0; I<N; I++) F = F + C[I]*X[I]; • ASSEMBLER ; LOOP INITIATION CODE MOV R0,#0 ; USE R0 FOR I MOV R8,#0 ; USE SEPARATE INDEX FOR ARRAYS ADR R2,N ; GET ADDRESS FOR N LDR R1,[R2] ; GET VALUE OF N MOV R2,#0 ; USE R2 FOR F © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 32. FIR FILTER, CONT’.D ADR R3,C ; LOAD R3 WITH BASE OF C ADR R5,X ; LOAD R5 WITH BASE OF X ; LOOP BODY LOOP LDR R4,[R3,R8] ; GET C[I] LDR R6,[R5,R8] ; GET X[I] MUL R4,R4,R6 ; COMPUTE C[I]*X[I] ADD R2,R2,R4 ; ADD INTO RUNNING SUM ADD R8,R8,#4 ; ADD ONE WORD OFFSET TO ARRAY INDEX ADD R0,R0,#1 ; ADD 1 TO I CMP R0,R1 ; EXIT? BLT LOOP ; IF I < N, CONTINUE © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 33. ARM SUBROUTINE LINKAGE • BRANCH AND LINK INSTRUCTION: BL FOO • COPIES CURRENT PC TO R14. • TO RETURN FROM SUBROUTINE: MOV R15,R14 © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 34. NESTED SUBROUTINE CALLS • NESTING/RECURSION REQUIRES CODING CONVENTION: F1 LDR R0,[R13] ; LOAD ARG INTO R0 FROM STACK ; CALL F2() STR R13!,[R14] ; STORE F1’S RETURN ADRS STR R13!,[R0] ; STORE ARG TO F2 ON STACK BL F2 ; BRANCH AND LINK TO F2 ; RETURN FROM F1() SUB R13,#4 ; POP F2’S ARG OFF STACK LDR R13!,R15 ; RESTORE REGISTER AND RETURN © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.
  • 35. SUMMARY • LOAD/STORE ARCHITECTURE • MOST INSTRUCTIONS ARE RISCY, OPERATE IN SINGLE CYCLE. • SOME MULTI-REGISTER OPERATIONS TAKE LONGER. • ALL INSTRUCTIONS CAN BE EXECUTED CONDITIONALLY. © 2008 Wayne WolfOverheads for Computers as Components 2nd ed.