microprocessor and interfacing 261313 pic code execution

14
Microprocessor and Interfacing 261313 PIC Code Execution http://www.e-cpe.org/moodle

Upload: esther-harper

Post on 31-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microprocessor and Interfacing 261313 PIC Code Execution

Microprocessor and Interfacing

261313

PIC Code Execution

http://www.e-cpe.org/moodle

Page 2: Microprocessor and Interfacing 261313 PIC Code Execution

How does the CPU executes this simple program?

void main() {

int i;

i = 1; i++;

}

Page 3: Microprocessor and Interfacing 261313 PIC Code Execution

Assembly Code

MOVLW 01BCF 03.5MOVWF 21INCF 21,F

Page 4: Microprocessor and Interfacing 261313 PIC Code Execution

Machine Code

11000000000001010010100000110000001010000100101010100001

Page 5: Microprocessor and Interfacing 261313 PIC Code Execution
Page 6: Microprocessor and Interfacing 261313 PIC Code Execution
Page 7: Microprocessor and Interfacing 261313 PIC Code Execution

File Register Map

Page 8: Microprocessor and Interfacing 261313 PIC Code Execution

Status Register (Address 03)

Zero Bit = จะเป็�น 0 เมื่อใดก็�ตามื่ที่� ALU คำ�านวณคำ�าออก็มื่าเป็�น 0

Page 9: Microprocessor and Interfacing 261313 PIC Code Execution

The 4 Qs

Q1 = Instruction Decode

Q2 = Fetch Operand

Q3 = Process the Data

Q4 = Write Result Data

Page 10: Microprocessor and Interfacing 261313 PIC Code Execution

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

Page 11: Microprocessor and Interfacing 261313 PIC Code Execution

Pipeline interruption

Flash->Ins Reg Q1 Q2 Q3 Q4

Flash->Ins Reg

Flash->Ins Reg Q1 Q2 Q3 Q4

time

Goto 323

Fetch Execute

Page 12: Microprocessor and Interfacing 261313 PIC Code Execution

Program Execution Example

.................... int i;

....................

.................... i=1; 000D: MOVLW 01000E: BCF 03.5000F: MOVWF 21.................... i++; 0010: INCF 21,F

Page 13: Microprocessor and Interfacing 261313 PIC Code Execution

Converting Assembly to Machine Code

11000000000001MOVLW 01BCF 03.5MOVWF 21INCF 21,F

010010100000110000001010000100101010100001

Page 14: Microprocessor and Interfacing 261313 PIC Code Execution

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