Beruflich Dokumente
Kultur Dokumente
ARM
ARM
ARM
ARM
ARM
ARM
versions.
assembly language.
programming model.
memory organization.
data operations.
flow of control.
ARM versions
ARM architecture has been extended
over several versions.
We will concentrate on ARM7.
label
LDRr0,[r8];acomment
ADDr4,r0,r1
r8
r9
r10
r11
r12
r13
r14
r15 (PC)
31
CPSR
NZCV
Endianness
Relationship between bit and byte/word
ordering defines endianness:
bit 31
bit 0
bit 0
little-endian
bit 31
big-endian
Examples:
-1 + 1 = 0: NZCV = 0110.
231-1+1 = -231: NZCV = 0101.
Immediate operand:
ADDr0,r1,#2
Computes r1+2, stores in r0.
Arithmetic shift:
fills with ones.
ARM comparison
instructions
CMP : compare
CMN : negated compare
TST : bit-wise test
TEQ : bit-wise negated test
These instructions set only the NZCV
bits of CPSR.
ARM load/store
instructions
LDR, LDRH, LDRB : load (half-word,
byte)
STR, STRH, STRB : store (half-word,
byte)
Addressing modes:
register indirect : LDRr0,[r1]
with second register : LDRr0,[r1,r2]
with constant : LDRr0,[r1,#4]
2008 Wayne Wolf
Example: C assignments
C:
x=(a+b)c;
Assembler:
ADRr4,a
LDRr0,[r4]
ADRr4,b
LDRr1,[r4]
ADDr3,r0,r1
ADRr4,c
LDRr2[r4]
v
;getaddressfora
;getvalueofa
;getaddressforb,reusingr4
;getvalueofb
;computea+b
;getaddressforc
;getvalueofc
Overheads for Computers as
Components 2nd ed.
C assignment, contd.
SUBr3,r3,r2
ADRr4,x
STRr3[r4]
;completecomputationofx
;getaddressforx
;storevalueofx
Example: C assignment
C:
y=a*(b+c);
Assembler:
ADRr4,b;getaddressforb
LDRr0,[r4];getvalueofb
ADRr4,c;getaddressforc
LDRr1,[r4];getvalueofc
ADDr2,r0,r1;computepartialresult
ADRr4,a;getaddressfora
LDRr0,[r4];getvalueofa
2008 Wayne Wolf
C assignment, contd.
MULr2,r2,r0;computefinalvaluefory
ADRr4,y;getaddressfory
STRr2,[r4];storey
Example: C assignment
C:
z=(a<<2)|(b&15);
Assembler:
ADRr4,a;getaddressfora
LDRr0,[r4];getvalueofa
MOVr0,r0,LSL2;performshift
ADRr4,b;getaddressforb
LDRr1,[r4];getvalueofb
ANDr1,r1,#15;performAND
ORRr1,r0,r1;performOR
2008 Wayne Wolf
C assignment, contd.
ADRr4,z;getaddressforz
STRr1,[r4];storevalueforz
Additional addressing
modes
Base-plus-offset addressing:
LDRr0,[r1,#16]
Loads from location r1+16
Branch operation:
B#100
Can be performed conditionally.
Example: if statement
C:
if(a>b){x=5;y=c+d;}elsex=cd;
Assembler:
;computeandtestcondition
ADRr4,a;getaddressfora
LDRr0,[r4];getvalueofa
ADRr4,b;getaddressforb
LDRr1,[r4];getvalueforb
CMPr0,r1;comparea<b
BGEfblock;ifa>=b,branchtofalseblock
2008 Wayne Wolf
If statement, contd.
;trueblock
MOVr0,#5;generatevalueforx
ADRr4,x;getaddressforx
STRr0,[r4];storex
ADRr4,c;getaddressforc
LDRr0,[r4];getvalueofc
ADRr4,d;getaddressford
LDRr1,[r4];getvalueofd
ADDr0,r0,r1;computey
ADRr4,y;getaddressfory
STRr0,[r4];storey
Bafter;brancharoundfalseblock
2008 Wayne Wolf
If statement, contd.
;falseblock
fblockADRr4,c;getaddressforc
LDRr0,[r4];getvalueofc
ADRr4,d;getaddressford
LDRr1,[r4];getvalueford
SUBr0,r0,r1;computeab
ADRr4,x;getaddressforx
STRr0,[r4];storevalueofx
after...
Example: Conditional
instruction implementation
;trueblock
MOVLTr0,#5;generatevalueforx
ADRLTr4,x;getaddressforx
STRLTr0,[r4];storex
ADRLTr4,c;getaddressforc
LDRLTr0,[r4];getvalueofc
ADRLTr4,d;getaddressford
LDRLTr1,[r4];getvalueofd
ADDLTr0,r0,r1;computey
ADRLTr4,y;getaddressfory
STRLTr0,[r4];storey
2008 Wayne Wolf
Assembler:
ADRr2,test;getaddressfortest
LDRr0,[r2];loadvaluefortest
ADRr1,switchtab;loadaddressforswitchtable
LDRr1,[r1,r0,LSL#2];indexswitchtable
switchtabDCDcase0
DCDcase1
...
2008 Wayne Wolf
Assembler
;loopinitiationcode
MOVr0,#0;user0forI
MOVr8,#0;useseparateindexforarrays
ADRr2,N;getaddressforN
LDRr1,[r2];getvalueofN
MOVr2,#0;user2forf
2008 Wayne Wolf
LDRr0,[r13];loadargintor0fromstack
;callf2()
STRr13!,[r14];storef1sreturnadrs
STRr13!,[r0];storeargtof2onstack
BLf2;branchandlinktof2
;returnfromf1()
SUBr13,#4;popf2sargoffstack
LDRr13!,r15;restoreregisterandreturn
Summary
Load/store architecture
Most instructions are RISCy, operate
in single cycle.
Some multi-register operations take
longer.