Microprocessor and Interfacing 261313 PIC Code Execution http

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

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

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

Assembly Code MOVLW BCF MOVWF INCF 01 03. 5 21 21, F

Assembly Code MOVLW BCF MOVWF INCF 01 03. 5 21 21, F

Machine Code 110000001 01001010000011 00000010100001

Machine Code 110000001 01001010000011 00000010100001

File Register Map See figure 6 -5 in the handout For a complete File

File Register Map See figure 6 -5 in the handout For a complete File Register layout

Status Register (Address 03) Zero Bit = ������ 0 ������ ALU ������ 0 See

Status Register (Address 03) Zero Bit = ������ 0 ������ ALU ������ 0 See section “Register 5 -1” in the handout for details of the Status Register

The 4 Qs Q 1 = Instruction Decode Q 2 = Fetch Operand Q

The 4 Qs Q 1 = Instruction Decode Q 2 = Fetch Operand Q 3 = Process the Data Q 4 = Write Result Data See section 4. 2, 4. 3 in the handout for details

Instruction Pipeline Flow Fetch Cmd 1 Cmd 2 Cmd 3 Execute Flash->Ins Reg Q

Instruction Pipeline Flow Fetch Cmd 1 Cmd 2 Cmd 3 Execute Flash->Ins Reg Q 1 Q 2 Q 3 Q 4 time Q 1 = Instruction Decode Q 2 = Fetch Operand Q 3 = Process the Data Q 4 = Write Result Data

Pipeline interruption Fetch Goto 3 Cmd 2 Cmd 3 Execute Flash->Ins Reg Q 1

Pipeline interruption Fetch Goto 3 Cmd 2 Cmd 3 Execute Flash->Ins Reg Q 1 Q 2 Q 3 Q 4 time Q 1 = Instruction Decode Q 2 = Fetch Operand Q 3 = Process the Data Q 4 = Write Result Data

Program Execution Example. . . . 000 D: MOVLW 01 000 E: BCF 03.

Program Execution Example. . . . 000 D: MOVLW 01 000 E: BCF 03. 5 000 F: MOVWF 21. . . . . 0010: INCF 21, F int i; i=1; i++;

Converting Assembly to Machine Code MOVLW BCF MOVWF INCF 01 03. 5 21 21,

Converting Assembly to Machine Code MOVLW BCF MOVWF INCF 01 03. 5 21 21, F 110000001 01001010000011 00000010100001 Look at table 5 -1 in the handout for the machine code reference

Program Execution Ex 2. . . . . 000 D: MOVLW 05 000 E:

Program Execution Ex 2. . . . . 000 D: MOVLW 05 000 E: BCF 03. 5 000 F: MOVWF 21. . . . . 0010: DECF 21, F. . . . . 0011: MOVF 21, F 0012: BTFSS 03. 2 0013: GOTO 010 int i; i = 5; do { i--; } while (i>0);