PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++;...
-
Upload
aubrey-craig -
Category
Documents
-
view
224 -
download
0
description
Transcript of PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++;...
![Page 1: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/1.jpg)
Microprocessor and Interfacing261214
PIC Code Execution
http://mango.e-cpe.org
![Page 2: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/2.jpg)
How does the CPU executes this simple program?void main()
{ int
i;
i = 1; i+
+;}
![Page 3: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/3.jpg)
Assembly CodeMOVLW 01BCF 03.5MOVWF 21INCF 21,F
![Page 4: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/4.jpg)
Machine Code11000000000001010010100000110000001010000100101010100001
![Page 5: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/5.jpg)
![Page 6: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/6.jpg)
![Page 7: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/7.jpg)
File Register Map
See figure 6-5 in the handoutFor a complete File Register layout
![Page 8: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/8.jpg)
The 4 QsQ1 = Instruction DecodeQ2 = Fetch OperandQ3 = Process the DataQ4 = Write Result Data
See section 4.2, 4.3 in the handout for details
![Page 9: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/9.jpg)
Instruction Pipeline Flow
time
Cmd1Cmd2Cmd3
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg Q1 Q2 Q3 Q4
Fetch Execute
Q1 = Instruction Decode
Q2 = Fetch OperandQ3 = Process the DataQ4 = Write Result
Data
![Page 10: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/10.jpg)
Pipeline interruption
time
Q1 = Instruction Decode
Q2 = Fetch OperandQ3 = Process the DataQ4 = Write Result
Data
Goto 3Cmd2Cmd3
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg
Flash->Ins Reg Q1 Q2 Q3 Q4
Fetch Execute
![Page 11: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/11.jpg)
Program Execution Example.................... int i; .................... .................... i=1; 000D: MOVLW 01000E: BCF 03.5000F: MOVWF 21.................... i++; 0010: INCF 21,F
![Page 12: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/12.jpg)
Converting Assembly to Machine Code
11000000000001MOVLW 01BCF 03.5MOVWF 21INCF 21,F
010010100000110000001010000100101010100001
Look at table 5-1 in the handout for the machine code reference
![Page 13: PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }](https://reader036.fdocuments.net/reader036/viewer/2022062412/5a4d1afc7f8b9ab05998438f/html5/thumbnails/13.jpg)
Program Execution Ex 2.................... int i; .................... i = 5; 000D: MOVLW 05000E: BCF 03.5000F: MOVWF 21.................... do { .................... i--; 0010: DECF 21,F.................... } while (i>0); 0011: MOVF 21,F0012: BTFSS 03.2 0013: GOTO 010