pic code execution how does the cpu executes this simple program? void main() { int i; i = 1; i++;...

13
Microprocessor and Interfacing 261214 PIC Code Execution http://mango.e-cpe.org

Upload: aubrey-craig

Post on 17-Jan-2018

224 views

Category:

Documents


0 download

DESCRIPTION

Assembly Code MOVLW 01 BCF 03.5 MOVWF 21 INCF 21,F

TRANSCRIPT

Page 1: PIC Code Execution  How does the CPU executes this simple program? void main() { int i; i = 1; i++; }

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++; }

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++; }

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++; }

Machine Code11000000000001010010100000110000001010000100101010100001

Page 5: PIC Code Execution  How does the CPU executes this simple program? void main() { int i; i = 1; i++; }
Page 6: PIC Code Execution  How does the CPU executes this simple program? void main() { int i; i = 1; i++; }
Page 7: PIC Code Execution  How does the CPU executes this simple program? void main() { int i; i = 1; i++; }

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++; }

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++; }

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++; }

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++; }

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++; }

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++; }

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