Professional Documents
Culture Documents
Section 5. CPU and ALU: Highlights
Section 5. CPU and ALU: Highlights
5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11
HIGHLIGHTS
This section of the manual contains the following major topics: Introduction ....................................................................................................................5-2 General Instruction Format ............................................................................................5-4 Central Processing Unit (CPU) ......................................................................................5-4 Instruction Clock ............................................................................................................5-4 Arithmetic Logical Unit (ALU).........................................................................................5-5 STATUS Register ...........................................................................................................5-6 OPTION_REG Register .................................................................................................5-8 PCON Register ..............................................................................................................5-9 Design Tips ..................................................................................................................5-10 Related Application Notes............................................................................................5-11 Revision History ...........................................................................................................5-12
5
CPU and ALU
DS31005A-page 5-2
BYTE-ORIENTED FILE REGISTER OPERATIONS 1,2 C,DC,Z ffff 0111 dfff 00 1 Add W and f f, d ADDWF 1,2 Z ffff 0101 dfff 00 1 AND W with f f, d ANDWF 2 Z ffff 0001 lfff 00 1 Clear f f CLRF Z xxxx 0001 0xxx 00 1 Clear W CLRW 1,2 Z ffff 1001 dfff 00 1 Complement f f, d COMF 1,2 Z ffff 0011 dfff 00 1 Decrement f f, d DECF 1,2,3 ffff 1011 dfff 00 1(2) Decrement f, Skip if 0 f, d DECFSZ 1,2 Z ffff 1010 dfff 00 1 Increment f f, d INCF 1,2,3 ffff 1111 dfff 00 1(2) Increment f, Skip if 0 f, d INCFSZ 1,2 Z ffff 0100 dfff 00 1 Inclusive OR W with f f, d IORWF 1,2 Z ffff 1000 dfff 00 1 Move f f, d MOVF ffff 0000 lfff 00 1 Move W to f f MOVWF 0000 0000 0xx0 00 1 No Operation NOP 1,2 C ffff 1101 dfff 00 1 Rotate Left f through Carry f, d RLF 1,2 C ffff 1100 dfff 00 1 Rotate Right f through Carry f, d RRF 1,2 C,DC,Z ffff 0010 dfff 00 1 Subtract W from f f, d SUBWF 1,2 ffff 1110 dfff 00 1 Swap nibbles in f f, d SWAPF 1,2 Z ffff 0110 dfff 00 1 Exclusive OR W with f f, d XORWF BIT-ORIENTED FILE REGISTER OPERATIONS ffff 1,2 00bb bfff 1 01 Bit Clear f f, b BCF ffff 1,2 01bb bfff 1 01 Bit Set f f, b BSF 3 10bb bfff- ffff 1 (2) 01 Bit Test f, Skip if Clear f, b BTFSC ffff 3 11bb bfff 1 (2) 01 Bit Test f, Skip if Set f, b BTFSS LITERAL AND CONTROL OPERATIONS C,DC,Z kkkk 111x kkkk 11 1 Add literal and W k ADDLW Z kkkk 1001 kkkk 11 1 AND literal with W k ANDLW kkkk 0kkk kkkk 10 2 Call subroutine k CALL TO,PD 0100 0000 0110 00 1 Clear Watchdog Timer CLRWDT kkkk 1kkk kkkk 10 2 Go to address k GOTO kkkk 1000 kkkk 11 1 Inclusive OR literal with W k IORLW Z kkkk 00xx kkkk 11 1 Move literal to W k MOVLW 1001 0000 0000 00 2 Return from interrupt RETFIE kkkk 01xx kkkk 11 2 Return with literal in W k RETLW 1000 0000 0000 00 2 Return from Subroutine RETURN 0011 0000 0110 00 1 Go into standby mode SLEEP TO,PD kkkk 110x kkkk 11 1 Subtract W from literal k SUBLW C,DC,Z kkkk 1010 kkkk 11 1 Exclusive OR literal with W k XORLW Z Note 1: When an I/O register is modied as a function of itself ( e.g., MOVF PORTB, 1), the value used will be that value present on the pins themselves. For example, if the data latch is '1' for a pin congured as input and is driven low by an external device, the data will be written back with a '0'. 2: If this instruction is executed on the TMR0 register (and, where applicable, d = 1), the prescaler will be cleared if assigned to the Timer0 Module. 3: If Program Counter (PC) is modied or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.
5
CPU and ALU
DS31005A-page 5-3
Bit-oriented le register operations 13 10 9 7 6 OPCODE b (BIT #) f (FILE #) Literal and control operations General 13 OPCODE CALL and GOTO instructions only 13 11 OPCODE 10 k (literal) 8 7 k (literal)
5.3
5.4
Instruction Clock
Each instruction cycle (TCY) is comprised of four Q cycles (Q1-Q4). The Q cycle time is the same as the device oscillator cycle time (TOSC). The Q cycles provide the timing/designation for the Decode, Read, Process Data, Write, etc., of each instruction cycle. The following diagram shows the relationship of the Q cycles to the instruction cycle. The four Q cycles that make up an instruction cycle (TCY) can be generalized as: Q1: Q2: Q3: Q4: Instruction Decode Cycle or forced No operation Instruction Read Data Cycle or No operation Process the Data Instruction Write Data Cycle or No operation
Each instruction will show a detailed Q cycle operation for the instruction. Figure 5-2: Q Cycle Activity
Q1 Tosc Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
TCY1
TCY2
TCY3
DS31005A-page 5-4
8 W Register 8
ALU
8 d bit, or from instruction d = '0' or Literal Instructions d = '1'
The ALU is 8-bits wide and is capable of addition, subtraction, shift and logical operations. Unless otherwise mentioned, arithmetic operations are two's complement in nature. In two-operand instructions, typically one operand is the working register (W register). The other operand is a le register or an immediate constant. In single operand instructions, the operand is either the W register or a le register. The W register is an 8-bit working register used for ALU operations. It is not an addressable register. Depending on the instruction executed, the ALU may affect the values of the Carry (C), Digit Carry (DC), and Zero (Z) bits in the STATUS register. The C and DC bits operate as a borrow bit and a digit borrow out bit, respectively, in subtraction. See the SUBLW and SUBWF instructions for examples.
5
CPU and ALU
DS31005A-page 5-5
DS31005A-page 5-6
R/W-0 RP1
R/W-0 RP0
R-1 TO
R-1 PD
R/W-x Z
R/W-x DC
R/W-x C bit 0
IRP: Register Bank Select bit (used for indirect addressing) 1 = Bank 2, 3 (100h - 1FFh) 0 = Bank 0, 1 (00h - FFh) For devices with only Bank0 and Bank1 the IRP bit is reserved, always maintain this bit clear. RP1:RP0: Register Bank Select bits (used for direct addressing) 11 = Bank 3 (180h - 1FFh) 10 = Bank 2 (100h - 17Fh) 01 = Bank 1 (80h - FFh) 00 = Bank 0 (00h - 7Fh) Each bank is 128 bytes. For devices with only Bank0 and Bank1 the IRP bit is reserved, always maintain this bit clear.
bit 6:5
bit 4
TO: Time-out bit 1 = After power-up, CLRWDT instruction, or SLEEP instruction 0 = A WDT time-out occurred PD: Power-down bit 1 = After power-up or by the CLRWDT instruction 0 = By execution of the SLEEP instruction Z: Zero bit 1 = The result of an arithmetic or logic operation is zero 0 = The result of an arithmetic or logic operation is not zero DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions) (for borrow the polarity is reversed) 1 = A carry-out from the 4th low order bit of the result occurred 0 = No carry-out from the 4th low order bit of the result C: Carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions) 1 = A carry-out from the most signicant bit of the result occurred 0 = No carry-out from the most signicant bit of the result occurred Note: For borrow the polarity is reversed. A subtraction is executed by adding the twos complement of the second operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low order bit of the source register.
bit 3
bit2
bit 1
bit 0
Legend R = Readable bit W = Writable bit - n = Value at POR reset U = Unimplemented bit, read as 0
5
CPU and ALU
DS31005A-page 5-7
RBPU: PORTB Pull-up Enable bit 1 = PORTB pull-ups are disabled 0 = PORTB pull-ups are enabled by individual port latch values INTEDG: Interrupt Edge Select bit 1 = Interrupt on rising edge of INT pin 0 = Interrupt on falling edge of INT pin T0CS: TMR0 Clock Source Select bit 1 = Transition on T0CKI pin 0 = Internal instruction cycle clock (CLKOUT) T0SE: TMR0 Source Edge Select bit 1 = Increment on high-to-low transition on T0CKI pin 0 = Increment on low-to-high transition on T0CKI pin PSA: Prescaler Assignment bit 1 = Prescaler is assigned to the WDT 0 = Prescaler is assigned to the Timer0 module PS2:PS0: Prescaler Rate Select bits
Bit Value 000 001 010 011 100 101 110 111 TMR0 Rate 1:2 1:4 1:8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 WDT Rate 1:1 1:2 1:4 1:8 1 : 16 1 : 32 1 : 64 1 : 128
bit 6
bit 5
bit 4
bit 3
bit 2-0
Legend R = Readable bit W = Writable bit - n = Value at POR reset U = Unimplemented bit, read as 0
Note:
To achieve a 1:1 prescaler assignment for the TMR0 register, assign the prescaler to the Watchdog Timer.
DS31005A-page 5-8
MPEEN: Memory Parity Error Circuitry Status bit This bit reects the value of the MPEEN conguration bit. Unimplemented: Read as '0' PER: Memory Parity Error Reset Status bit 1 = No error occurred 0 = A program memory fetch parity error occurred (must be set in software after a Power-on Reset occurs) POR: Power-on Reset Status bit 1 = No Power-on Reset occurred 0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs) BOR: Brown-out Reset Status bit 1 = No Brown-out Reset occurred 0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs) Legend R = Readable bit W = Writable bit - n = Value at POR reset U = Unimplemented bit, read as 0
bit 1
bit 0
5
CPU and ALU
DS31005A-page 5-9
Question 2: Answer 2:
if the STATUS register is the destination for an instruction that affects the Z, DC, or C bits, the write to these bits is disabled. These bits are set or cleared based on device logic. Therefore, to modify bits in the STATUS register it is recommended to use the BCF and BSF instructions.
DS31005A-page 5-10
5
CPU and ALU
DS31005A-page 5-11
DS31005A-page 5-12