150 likes | 304 Views
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 01 BCF 03.5 MOVWF 21 INCF 21,F. Machine Code. 11000000000001 01001010000011
E N D
Microprocessor and Interfacing261313 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 01 BCF 03.5 MOVWF 21 INCF 21,F
Machine Code 11000000000001 01001010000011 00000010100001 00101010100001
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
Q1 Q1 Q1 Q2 Q2 Q2 Q3 Q3 Q3 Q4 Q4 Q4 Instruction Pipeline Flow Execute Fetch 1 2 3 Flash->Ins Reg Flash->Ins Reg Flash->Ins Reg time
Q1 Q1 Q2 Q2 Q3 Q3 Q4 Q4 Pipeline interruption Execute Fetch Goto 3 2 3 Flash->Ins Reg Flash->Ins Reg Flash->Ins Reg time
Program Execution Example .................... int i; .................... .................... i=1; 000D: MOVLW 01 000E: BCF 03.5 000F: MOVWF 21 .................... i++; 0010: INCF 21,F
Converting Assembly to Machine Code MOVLW 01 BCF 03.5 MOVWF 21 INCF 21,F 11000000000001 01001010000011 00000010100001 00101010100001
Program Execution Ex 2 .................... int i; .................... i = 5; 000D: MOVLW 05 000E: BCF 03.5 000F: MOVWF 21 .................... do { .................... i--; 0010: DECF 21,F .................... } while (i>0); 0011: MOVF 21,F 0012: BTFSS 03.2 0013: GOTO 010