ARM????? - PowerPoint PPT Presentation

Loading...

PPT – ARM????? PowerPoint presentation | free to download - id: 7b97e3-YmRmM



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

ARM?????

Description:

Title: ARM Author: nakata Last modified by: Created Date: 7/22/2006 5:28:44 AM Document presentation format: – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 80
Provided by: nak83
Learn more at: http://cis.k.hosei.ac.jp
Category:
Tags: arm | project | swine

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: ARM?????


1
ARM?????
  • ARM ????
  • ARM Software Development Toolkit(???????)
  • http//cis.k.hosei.ac.jp/nakata/lectureMachin
    e/202u_w32_v1.zip
  • ARM Developer Suite(??? 45??)
  • S. Furber?/???(?)?????ARM??????CQ???
  • (2) DevKitAdv
  • http//devkitadv.sourceforge.net/index.html
  • (3) GCC
  • Linux/GBA?
  • ?????Linux????????????????
  • ?????? ???????
  • Linux/Zaurus?
  • http//www.nk.rim.or.jp/jun/slasm/arm00.html
  • Linux Zaurus?????????????

2
ARM Software Development Toolkit???????
(1) 202u_w32_v1.zip?????????ARM202U ? C\ARM202U
???? C\ARMProject????????????? (2)
C\ARM202U\BIN\APM.EXE???????????????? Project
-gt New... ?????? C\ARMProject\test1.apj ???????T
EST1.APJ??????????C\ARMProject\
?????(??????????????????) Options -gt
Directories... ? C\ARM200 ?????????(3????)? C\
ARM202U ?????(????? C\ARM200\BIN\ ?
C\ARM202U\BIN\ ???)?
3
???????? ?????
4
ARM Software Development Toolkit???(???????)
APM(ARM Project Manager)? File -gt
new ?Untitled1??????????????????(????)?????? ?????
??????????????????
AREA test,CODE ??AREA??test,CODE??? ENTRY
??ENTRY?????????????? LDR R0, X
??LDR??R0, X???? R0 X LDR R1, Y R1 Y
LDR?Load Register ADD R0, R0, R1 R0 R0
R1 STR R0, Z STR?Store Register, Z
R0 X DCD 15 X?????(DCD Define
Constant)15 Y DCD 21 Y?????21 Z DCD 0
Z?????0 END end of program
X,Y,Z???????? ?????????? ??????????
??? test1.s ??????ARMProject??????
5
ARM Software Development Toolkit???(????????)
APM(ARM Project Manager)? Project -gt
edit... ?test1.s???????TEST1.APJ??????? (?????????
??????????????????????????????
????????????????????????????) ?? Project -gt
Build TEST1.APJ ??????????????????????????????????
?????????????? Building... Linking
(C\ARMPROJ\TEST1) ... Build Complete. ?????????
????
6
??????????????
7
ARM Software Development Toolkit???(??1)
APM(ARM Project Manager)? Project -gt Debug
TEST1.APJ ??????????ARM Debugger????????? Executi
on Window (8008??????????????16???) Console
Window ???????? View -gt Registers -gt User
Mode ?????User Registers???????????2???PC?????15??
??????????????????????????8008????????? Execute
-gt Step ?????????Step????????????
800c??????????? bl test ????????(test????????????
?????)? ???? Execute -gt Step In ?????????Step
Into???????????????test???(??????)?Execution
Window????test1.s????? User Registers?PC?????????8
080???????????????????8080???
8
Project -gt Debug TEST1.APJ ??????
9
View -gt Registers -gt User Mode
Execute -gt Step Execute -gt Step In ??????
10
ARM Software Development Toolkit???(??2)
View -gt Memory... ?????8080???????????????????Mem
ory Window?????????????? LDR R0, X ??????
0xe59f0008 8090???10??15(16???f) 8094???10??21(1
6???15)? ???? Execute -gt Step In ???(Execute -gt
Step???????)?8080???????????? User
Registers????X??(8090??)???r0?????????????? ??????
??????????? r1?0x15??????? ???f?????0x24?r0????
???Z??(8098??)????(??)??? ? X?Y?Z????????????????
View -gt Low Level Symbols ?????????????????
11
View -gt Memory...
?8080???
Execute -gt Step In ?8080????????
12
STR??????
View -gt Low Level Symbols ?????????????
13
ARM Software Development Toolkit???(??3)
??????????????????????? ??????????? 0x0000000f ??
????????????????? ???????????????????? View -gt
Disassembly... ( Disassembly??????????????) ?????
8080???8090??????????? ??????? 0x0000000f ???????
? andeq r0, r0, pc ??????????????????r0???0????
?????????????????? ???????????????????????????????
??????????????????????????????????????????????????
PC????????????????????????????????????????????????
???????????????
14
View -gt Disassembly...
15
??2
R0 0 R1 1 R2 10 i 0 do R0 R0
R1 Outi R0 i i 1
while (R0 ! R2)
AREA test2, CODE ENTRY LDR R0, M0 LDR R1,
M1 LDR R2, M10 LDR R3, A_Out
Out0??? L1 add R0, R0, R1 str R0, R3
Out0 , Out1,,????? ADD R3, R3,
4 R3 Outi???i1,2,3,... CMP R0,
R2 compare R0 and R2 BNE L1
if (R0 ! R2) go to L1 SWI 0x11
Software Interrupt 0x11 ?Halt M0 DCD 0
??0 M1 DCD 1 ??1 M10 DCD 10
??10 A_Out DCD Out A_Out????
Out??(??) AREA block, DATA, READWRITE Out 40
"" ?0????????40? END
Out0, Out1,, Out9,
16
str????????????
17
CMP???10?????????
18
????????????
AREA test2, CODE ENTRY LDR R0, M0 LDR R1,
M1 LDR R2, M10 LDR R3, A_Out
L1 add R0, R0, R1 str R0, R3
ADD R3, R3, 4 CMP R0, R2
BNE L1 SWI 0x11 M0 DCD 0
M1 DCD 1 M10 DCD 10
A_Out DCD Out AREA block, DATA,
READWRITE Out 40 END
AREA,CODE,ENTRY,END ??????????? ADD, STR
?????? add, str???????????? R0,R1????????? r0,
r1???????????? L1,M0,A_Out??????? ???????????????
? ???????????????? ??????
19
??3
1??9??????????????? ????????????????? ???????????
????????????
R1 0 do R1 R1 1 R0 R1 0x30
WriteC(R0) while (R1 ! 10)
WriteC EQU 0x0 WriteC???0(0x0)??? AREA test3,
CODE ENTRY MOV R1, 0 R1 0
???????n?'n'?? L1 ADD R1, R1, 1 R1 R1
1 ADD R0, R1, 0x30 ??100000001???????0011000
1? SWI WriteC WriteC(R0) CMP R1,10
compute R1 - 10 and set Condition Code BNE L1
if (Z0 ????R1 ! 10) go to L1 SWI 0x11 END
20
JIS??????
??4???
??4 ??? ASCII?????\???\?
21
SWI 0??????????
22
ARM???????
ARM Advanced RISC Machine RISC Reduced
Instruction Set Computer (CISCComplex
Instruction Set Computer) RISC??? ???/???
??????? ????????????????/??? ??? ADD R0,
M1 ????????? ?????? ??????????
ARM??????32?????
23
????
???8??? ????(signed) -128 127
????(unsigned) 0 255 ??????16??? ????
-32768 32767 ???? 0 65535
2??????????(??????) ???32??? ????
-2147483648 2147483647 ???? 0
4294967295 4??????????(4???????) ????????????
(???)????????? ???????????
24
????
32?????????16???(??????????)? r0r15 r15 pc
(program counter) r14 lr(link register) r13
sp(stack pointer) CPSR Current Program Status
Register) ?????????????????????????? N
?(Negative)? ????(???????'1'???)'1'?
?????'0'????? Z ??(Zero)??????'1'??????????'0'??
??? C ???(Carry)???????????????????
????????????????????????????? V
???(oVerflow)????????????????
????????????????????
25
???????
????0??231-1?????????????????? ???????????????????
?? little endian
26
ARM???????
???ARM???????????gcc?ARM?????????
?????????????????????
AREA ?????????????????? ENTRY ?????????? END
???????????? ORG ?????????????????? IMPORT
??????????????????? EXPORT ?????????????????? A
LIGN ???????????????
27
???
????? ??? WS ??? WS ????
?????????????? WS(white space)???????????
?????????????????????WS?????? ? L1 ADD R1,R1,1
R1 R1 1 ADD R0,R1,0x30 ??1????????
28
???
?????? ??? WS EQU ? EQU?equate(?????)????????
? ?????????????????????? ? Abc EQU 100 ??100?
??????Abc?????????
29
???
??????????? ??? WS (DCBDCWDCD) WS
??? DCB(???)?DCW(??????)?DCD(???)? ???????? DC?D
efine Constant??? ?????????(1????????0)?????
? DCB4 DCB 'a', 0xff, 5, 0 DCW6 DCW 'a',
0xff, 5, 0, 12345, 0xffff DCD5 DCD 'a', 0xff,
12345, 0xffff, 0xffffff DCB "C_string",0 ???
DCB 'C', '_', 's', 't', 'r', 'i', 'n', 'g', 0
???
30
JIS??????
??4???
??4 ??? ASCII?????\???\?
31
???????(1)
???? ADD?SUB?ADC(???????)?SBC(???????)? RSB(???)
?RSC(????????) add r0, r1, r2 r0 r1
r2 sub r0, r1, r2 r0 r1 - r2 rsb r0,
r1, r2 r0 r2 - r1 ???? AND
??1??1??????????? 01010101 AND 00001111
00000101 (?4????????) ORR ?????1??1????
01010101 ORR 00001111 01011111 EOR(Exclusive
OR) ???????1?????????? 01010101 EOR 00001111
01011010 BIC ?2??????1??0? AND???????? BIC
r0,r1,r2 r0 r1 and not r2 01010101 BIC
00001111 01010000 (?4????0)
32
???????(2)
?????? MOV(??)?MVN(??????)? MOV r0, r2 r0
r2 MVN r0, r2 r0 not r2 ????(???cc(?????)??
??) CMP(??)?CMN(????????)?TST?TEQ CMP r1,
r2 compare set cc on r1 - r2 CMN r1, r2
compare negative set cc on r1 r2? TST r1,
r2 bit test set cc on r1 and r2 TEQ r1,
r2 bit test equal set cc on r1 eor
r2 ???????(immediate operand) ?????2?????????????
????? 8????????????????????0xff4?0xff64
ADD r3, r3, 1 r3 r3 1 MOV r4, 9 r4
9 AND r8,r7,0xff r8 r7???8???
33
??????????
34
???????(???)
?????????? LSL Logical Shift
Left ??????? ????????0 LSR Logical Shift
Right ??????? ????????0 ASR Arithmetic Shift
Right ??????????????? ?????????? ROR Rotate
Right ?????????? RRX Rotate Right
Extended (C????????? 1??????)
35
???????(????)
????????????????????operand2 ADD r3, r2, r1,
LSL 3 r3 r2 r123 ADD r5, r5, r3, LSL
r2 r5 r5 r32r2 logical
shift(?????)?? 1110 0000 1001 0000 0011 0000
0101 0010 ??LSR 4????4????????? 0000 1110 0000
1001 0000 0011 0000 0101 ????LSL
4????4????????? 1110 0000 1001 0000 0011 0000
0101 0000 arithmetic shift(?????)??
??m????????????2m???????????? 1110 0000 1001
0000 0011 0000 0000 0010 ???4??????????? 1111
1110 0000 1001 0000 0011 0000 0000
36
??????????(????)
?? MUL r4,r3,r2 r4 r3 r2???32??? ????????
????????????1???????????????? ?????????????????
MOV r0, r1, LSL 16 r0 r1 65536 ADD
r0, r1, r1, LSL 2 r0 r1 5 RSB r0, r1,
r1, LSL 3 r0 r1 7 View -gt Debugger
Internals ?????????clock????????? Options -gt
Debugger Configuration -gt ARMulator ?clock
speed?1MHz????? ?????????? ????????(?????)
ALU 1 ????ADD, SUB, MOV B, BL 3 ????
LDR 3 ????? 2 if Rd is pc. STR 2 ?????
MUL 1M ???? M 14(????????)
37
???????
LDR/STR?????
38
???????????????(1)
?????????????(Rn????????offset0) LDR
r0, r1 r0 memr1 r1???n????n??????
STR r0, r1 memr1 r0
PC?????????(Rnpc?offset?????????(12?????))
LDR R2, M10 M10???????PC?????
LDR R3, A_Out A_Out?PC???Out????????? ...
M10 DCD 10 A_Out DCD Out address of
Out(32???) AREA block, DATA Out
40 ????????????????? LDR R3,
Out ???????????A_Out????????????????
39
???????????????(2)
????????(Rn???????offset?????????)
pre-indexed??????? LDR r0, r1,4
r0 mem r1 4 ????????? LDR r0,
r1,4! r0 memr1 4 r1
r1 4 post-indexed??????? LDR r0,
r1, 4 r0 memr1 r1 r1
4
LDR r1, TABLE1 LDR r2, TABLE2 loop LDR
r0, r1, 4 STR r0, r2, 4 CMP r0,
0 BNE loop
i 0 j 0 do r0 TABLE2j
TABLE1i r0 while (r0 ! 0)
40
???????????????(3)
????????????(offset?????????????)
LDR r1, TABLE1 LDR r2,
TABLE2 MOV r3, 0 loop LDR r0,
r1, r3, LSL 2 STR r0, r2, r3, LSL
2 ADD r3, r3, 1 CMP r0,
0 BNE loop
i 0 do r0 TABLE2i TABLE1i r0
i while (r0 ! 0)
41
?????????
??????????????"B"?????? ???????????? LDRB r0,
r1 r0 mem8r1 r1??????1????????r0???????
8??? ???????????????0????
AREA Copy, CODE ENTRY
LDR r1, srcstr LDR
r0, dststr strcopy LDRB r2, r1,
1 STRB r2, r0, 1 CMP
r2, 0 BNE strcopy SWI
0x11
??????? 1??????????
AREA Strings, DATA srcstr DCB
"First string",0 dststr DCB "Second string",0
END
42
????
???????
(24-bit signed word offset)4
?????????8 ????(???)?????(PC?????????) 4????????
???????4???????????? 8?????????????PC????????????
43
??????
44
????
????????????????????? ???????????????????????????
?????????????? ??????????????????????
?????????????????? ??????????????????????????
CMP r0, 5 ADDNE r1, r1, r0 SUBNE r1,
r1, r2 BYPASS
CMP r0, 5 BEQ BYPASS ADD r1, r1, r0 SUB r1,
r1, r2 BYPASS

CMP r0, r1 CMPEQ r2, r3 ADDEQ r4,
r4, 1

if ((r0r1) (r2r3)) r4
45
????????
set 1 clear 0
46
SWI(Software Interrupt)??
SWI_WriteC (SWI 0) r0?1?????? SWI_Write0 (SWI 2)
r0??????(0???????)??? SWI_ReadC (SWI 4)
???????1??????r0???? SWI_Exit (SWI 0x11)
??????????????????? SWI_Clock (SWI 0x61)
?????1/100????r0??? SWI_Open (SWI 0x66)
r0?????????????????? r1?????????0 (read), 4
(write), 8 (apend) ????????????r0??????
??????????0?r0????? SWI_Close (SWI 0x68)
???????????? ??????????r0????????????0?r0??? SW
I_Write (SWI 0x69) ???????????????
r0??????????r1??????????r2?????? SWI_Read (SWI
0x6a) ??????????????? r0??????????r1?????????
?r2??????
47
????????(1)
AREA hello1,CODE SWI_WriteC EQU 0x0 SWI_Exit EQU
0x11 ENTRY START LDR r1, TEXT LOOP LDRB r0,
r1, 1 CMP r0, 0 SWINE SWI_WriteC BNE LOOP
SWI SWI_Exit TEXT DCB "Hello World" DCB
0x0d, 0x0a, 0 END 0x0a?Line Feed(??)? 0x0d?Carri
age Return(??) (unix???????0x0a??? ??????????0x0d?
??????)
r0?1????0????????????? r0?1????0??????????? "Hel
lo World"??????
48
????????(2)
write_only EQU 4 AREA hello2,CODE ENTRY start
LDR r0, filename MOV r1, write_only SWI SWI_Op
en MOV r5, r0 LDR r1, String MOV r2,
14 SWI SWI_Write MOV r0, r5 SWI SWI_Close SWI
SWI_Exit filename DCB "hello.txt",0 String DCB "H
ello World!" DCB 0x0d, 0x0a, 0 END
r0??????hello.txt????? r1???????????????? ????????
???????r0? ????hello.txt??????r5? ?????????????r1?
???????????r2? ????(r0???????????) r0???????????
????????????
49
Java?????????
String filename hello.txt BufferedReader
reader new BufferedReader(
new FileReader(filename)
) // ????hello.txt??????????????reader???? Strin
g line reader.readLine() //????reader???????1??
??line?? reader.close() // ??????????????????
50
Game Boy Advance(GBA)-1
CPU?ARM7 ???? ?? ????(????) 8/16/32??? ?
?RAM 0200 0000 - 0203 FFFF 256KB
3/3/6 ??RAM 0300 0000 - 0300 7FFF 32KB
1/1/1 I/O???? 0400 0000 - 0400 03FF 1KB
1/1/1 VRAM 0600 0000 - 0601 7FFF 96KB
1/1/2
??RAM???RAM?????????? I/O???????????????????????
VRAM?????????????????160????240???
????1??????2?????????RGB????????5???? 0BBBBBGGG
GGRRRRR 0111110000000000 7C00 1F/0/0 ???
0000001111100000 03E0 0/1F/0
???? 0000000000011111 001F
0/0/1F ??? 0111111111111111
7FFF 1F/1F/1F ?
0000000000000000 0000 0/0/0 ?
51
Game Boy Advance(GBA)-2
??????????????????????????????? ??????????
mov r1, 0x04000000 I/O base address
ldr r2, 0xF03 video mode 3
str r2, r1 display control
mov r3, 0x06000000 VRAM address
ldr r4, 0x7FFF 0x00007FFF ?????
str r4, r3 ???????? str
r4, r3, 4 2???????? str
r4, r3, 8 3???????? str r4,
r3, 12 4???????? loop b loop
?????
????????GBA???????VisualBoyAdvance???? GBA????????
??????????? ???ARM???.doc????
52
??????
??????1???????(routine)????? ??????(subroutine)
???????????????Java??????????? ???????????????
????????????(Java?main???????)? ?????????????????
?????????????? ??????????????????? ?????????(?????
?)??????????????? ?????BL(Branch with
Link)?????? BL m ????????????PC??(???????)? ??
??r14????m???????????????? MOV PC, r14 MOV
r15, lr ???????BL m???????????? "r14"?????"lr"???"
LR"(Link Register)????????
53
????????
void main() addsubr(15, 20) addsubr(30,
54) int addsubr (int r0, int r1)
return r0r1
start MOV r0, 15 Set up
parameters MOV r1, 20 BL addsubr Call
subroutine MOV r0, 30 Set up
parameters MOV r1, 54 BL addsubr Call
subroutine SWI 0x11 terminate addsubr
Subroutine addsubr ADD r0, r0, r1
r0 r0 r1 MOV pc, lr Return from
subroutine with result in r0
54
??????gcd(?????)
start MOV r0, 10 MOV r1, 4 BL gcd
r0 gcd(10, 4) STR r0,
result SWI 0x11 result DCD 0 gcd CMP
r0, r1 SUBGT r0, r0, r1 SUBLT r1, r1,
r0 BNE gcd MOV pc,lr
void main() int result gcd(10, 4) int
gcd(int r0, int r1) do if (r0 gt r1) r0
- r1 if (r0 lt r1) r1 - r0 while(r0 !
r1) return r0
55
????????????
main LDR r0, srcstr pointer to first
string LDR r1, dststr pointer to second
string BL strcopy copy the first into
second SWI 0x11 and exit srcstr DCB "This is
my first (source) string",0 dststr DCB "This is
my second (destination) string",0 ALIGN
realign address to word boundary strcopy LDRB r2,
r0, 1 load byte, then update
address STRB r2, r1, 1 store byte, then
update address CMP r2, 0 check for zero
terminator BNE strcopy keep going if
not MOV pc, lr return
56
?????????????????
start MOV r0, 15 Set up parameters MOV r1,
20 BL firstfunc Call firstfunc. lr
RA0 RA0 SWI 0x11 terminate firstfunc
Subroutine firstfunc ADD r0, r0, r1 r0 r0
r1 BL secondfunc Call secondfunc. lr
RA1 RA1 MOV pc, lr Return to RA1 !! (not
RA0) secondfunc Subroutine
secondfunc ADD r0, r0, 45 r0 r0
45 MOV pc, lr Return to RA1 firstfuc??????
57
????????????

???? g1 f1 f1 m1 m1 m1 (1)???
(2) ??? (3) ??? (6)???? (5) ???? (4)
???? ???????????????????????????


58
?????????????????
start MOV r0, 15 Set up parameters MOV r1,
20 BL firstfunc Call firstfunc. lr
RA0 RA0 SWI 0x11 terminate firstfunc
Subroutine firstfunc STR lr, sp, 4
?????????(RA0)??? ADD r0, r0, r1 r0 r0
r1 BL secondfunc Call secondfunc. lr
RA1 RA1 LDR pc, sp, -4! ??????
RA0?????????? secondfunc Subroutine
secondfunc STR lr, sp, 4
?????RA0???RA1??? ADD r0, r0, 45 r0 r0
45 LDR pc, sp, -4! ?????? RA1??????????
59
?????????factorial
fact??fact???????? ?????????????? ????????? ?????
?????????
static int fact(int n) if (n 1) return
1 return n fact(n-1)
fact STR lr, sp, 4 ???????????? STR R0,
sp, 4 R0?????n???????? SUBS R0, R0, 1
??n - 1?R0? BEQ fact1 if (n 1) goto
fact1 BL fact else fact(n - 1) factn LDR R1,
sp, -4! ??n?????R1? MUL R0, R1, R0 R0 n
fact(n - 1) LDR pc, sp, -4!
??????????? fact1 LDR R0, sp, -4!
??1fact(1)?????R0? LDR pc, sp, -4!
???????????
60
factorial?????(1)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
r0
3
r13(sp)
r14(lr)
main1
r15(pc)
fact
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
61
main?BL fact??????
62
factorial?????(2)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
r0
2
r13(sp)
r14(lr)
factn
3
main1
r15(pc)
fact
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
63
fact?BL fact??????????
64
factorial?????(3)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
r0
1
2
r13(sp)
factn
r14(lr)
factn
3
main1
r15(pc)
fact
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
65
fact?BL fact???2???????
66
factorial?????(4)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
1
r0
0
factn
2
r13(sp)
factn
r14(lr)
factn
3
main1
r15(pc)
fact1
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
67
fact?BEQ fact1???????
68
factorial?????(5)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
1
r0
1
factn
2
r13(sp)
factn
r14(lr)
factn
3
main1
r15(pc)
factn
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
69
factorial?????(6)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
1
r0
2
factn
r1
2
2
r13(sp)
factn
r14(lr)
factn
3
main1
r15(pc)
factn
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
70
fact?LDR pc???????
r0 1
71
factorial?????(7)
fact STR lr, sp, 4 STR R0, sp, 4 SUBS R0,
R0, 1 BEQ fact1 BL fact factn LDR R1, sp,
-4! MUL R0, R1, R0 LDR pc, sp,
-4! fact1 LDR R0, sp, -4! LDR pc, sp, -4!
1
r0
6
factn
r1
3
2
r13(sp)
factn
r14(lr)
factn
3
main1
r15(pc)
main1
????
main LDR sp, stackBegin MOV R0,
3 BL fact main1 STR R0, result result
fact(3) AREA stack,DATA,READWRITE s
tackBegin 1000
72
fact?LDR pc??????????
r0 2
73
????????????
??????????????????????????????? ??????????????????
?????????? ????calling convention??????
ARM?????ARM Procedure Call Standard ???? r0
?1?????????????? r1 ?2???????? r2
?3???????? r3 ?4???????? r4r8
?????(r9r13??????) ????? ???????????????????
caller save register caller????????save?? ?????
???????????????? callee save register
????callee?save?? ????????????????
74
??????factorial
??????????????????? lr(???? callee
save)?r4(callee save)?????
fact STMIA sp!,r4,lr ?????r4???????? MOV r
4, r0 r4 n SUBS r0, r0, 1 ??n -
1?r0? BEQ fact1 if (n 1) goto
fact1 BL fact else fact(n -
1) factn MUL r0, r4, r0 r0 n fact(n -
1) LDMDB sp!, r4, pc ??????????return fact1
MOV r0, 1 r0 1 ( fact(1) ) LDMDB
sp!, r4, pc ??????????return
75
?????????????????
????factsub.s
????factmain.s
EXPORT fact AREA factsub, CODE fact STMIA sp!,
r4,lr MOV r4, r0 SUBS r0, r0,
1 BEQ fact1 BL fact factn MUL r0, r4,
r0 LDMDB sp!, r4, pc fact1 MOV r0,
1 LDMDB sp!, r4, pc END
IMPORT fact AREA factmain,CODE ENTRY main LDR
sp, stackBegin MOV r0, 3 BL fact main1 STR r
0, result SWI 0x11 result DCD 0 AREA stack,DAT
A stackBegin 1000 END
?????????????????? ????EXPORT?????IMPORT
76
ARM???(1)
???? op2 ADDcS Rd, Rn, op2 Rd Rn
op2 Rm ADCcS Rd, Rn,
op2 Rd Rn op2 Carry
32bit_imm(5bit_non_0) SUBcS Rd, Rn, op2 Rd
Rn op2 Rm, LSL
5bit_imm SBCcS Rd, Rn, op2 Rd Rn op2
Not(Carry) Rm, LSR 5bit_imm RSBcS Rd, Rn,
op2 Rd op2 Rn Rm, ASR
5bit_imm RSCcS Rd, Rn, op2 Rd op2 Rn
Not(Carry) Rm, ROR 5bit_imm MULcS Rd, Rm,
Rs Rd Rm Rs (Rd ! Rm) Rm, LSL Rs ????
Rm,
LSR Rs ANDcS Rd, Rn, op2 Rd Rn AND op2
Rm, ASR Rs ORRcS Rd, Rn, op2 Rd Rn OR
op2 Rm, ROR Rs EORcS Rd, Rn, op2 Rd
Rn EOR op2 Rm, RRX BICcS Rd, Rn,
op2 Rd Rn AND NOT op2
??????S???????????????????(???NZCV)???? ??????c??
?????????????????????????? c EQ (Equal), NE (Not
Equal), MI (Minus), PL (Plus, Positive or zero)
GE (Greater or Equal), LT (Less Than), GT
(Greater Than), LE (Less than or Equal)
77
ARM???(2)
?????? MOVcS Rd, op2 Rd op2 MVNcS
Rd, op2 Rd 0xFFFFFFFF EOR op2
???? CMPcS Rn, op2 cc Rn op2
CMNcS Rn, op2 cc Rn op2 TSTcS Rn,
op2 cc Rn AND op2 TEQcS Rn, op2 cc Rn
EOR op2 ???? Bc label pc label
address BLc label lr pc, pc label address
??????S????????????????????????? ??????c??????????
?????????????????? c EQ (Equal), NE (Not Equal),
MI (Minus), PL (Plus, Positive or zero) GE
(Greater or Equal), LT (Less Than), GT (Greater
Than), LE (Less than or Equal)
78
ARM???(3)
????? LDRc Rd, addr Rd
addr LDRcB Rd, addr Rd0-7 byte from
addr, Rd8-310 LDMcDB Rd!, regs
Rd??regs?????regs? ??? STRc Rd, addr
addr Rd STRcB Rd, addr addr
Rd0-7 STMcIA Rd!, regs
regs?Rd?????regs? ??? ???????????? SWI
24bit_value
79
ARM???(4) ???????
addr label label?????(
PC??) value value???????(PC??)
Rn Rn???????(??????) Rn,
/-12bit_offset ???Rn ?????(??)????? Rn,
/-Rm Rn ?????(????)????? Rn,
/-Rm, LSL 5bit Rn ?????(????????) Rn,
/-12bit_offset! ????????????? Rn, /-Rm!
???????????? Rn, /-Rm, LSL 5bit!
????? Rn, /-12bit_offset ?????Rn?? Rn,
/-Rm ???Rn???? Rn, /-Rm, LSL 5bit
About PowerShow.com