pic code execution how does the cpu executes this simple program? void main() { int i; i = 1; i++;...
DESCRIPTION
Assembly Code MOVLW 01 BCF 03.5 MOVWF 21 INCF 21,FTRANSCRIPT
Microprocessor and Interfacing261214
PIC Code Execution
http://mango.e-cpe.org
How does the CPU executes this simple program?void main()
{ int
i;
i = 1; i+
+;}
Assembly CodeMOVLW 01BCF 03.5MOVWF 21INCF 21,F
Machine Code11000000000001010010100000110000001010000100101010100001
File Register Map
See figure 6-5 in the handoutFor a complete File Register layout
The 4 QsQ1 = Instruction DecodeQ2 = Fetch OperandQ3 = Process the DataQ4 = Write Result Data
See section 4.2, 4.3 in the handout for details
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
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
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
Look at table 5-1 in the handout for the machine code reference
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