Microprocessor and Interfacing 261313 PIC Code Execution .
-
Upload
esther-harper -
Category
Documents
-
view
214 -
download
0
Transcript of Microprocessor and Interfacing 261313 PIC Code Execution .
Microprocessor and Interfacing
261313
PIC Code Execution
http://www.e-cpe.org/moodle
How does the CPU executes this simple program?
void main() {
int i;
i = 1; i++;
}
Assembly Code
MOVLW 01BCF 03.5MOVWF 21INCF 21,F
Machine Code
11000000000001010010100000110000001010000100101010100001
File Register Map
Status Register (Address 03)
Zero Bit = จะเป็�น 0 เมื่อใดก็�ตามื่ที่� ALU คำ�านวณคำ�าออก็มื่าเป็�น 0
The 4 Qs
Q1 = Instruction Decode
Q2 = Fetch Operand
Q3 = Process the Data
Q4 = Write Result Data
Instruction Pipeline Flow
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg Q1 Q2 Q3 Q4
time
123
Fetch Execute
Pipeline interruption
Flash->Ins Reg Q1 Q2 Q3 Q4
Flash->Ins Reg
Flash->Ins Reg Q1 Q2 Q3 Q4
time
Goto 323
Fetch Execute
Program Execution Example
.................... int i;
....................
.................... i=1; 000D: MOVLW 01000E: BCF 03.5000F: MOVWF 21.................... i++; 0010: INCF 21,F
Converting Assembly to Machine Code
11000000000001MOVLW 01BCF 03.5MOVWF 21INCF 21,F
010010100000110000001010000100101010100001
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