Arithmetic Logic Instructions and Programs Chapter 5 Arithmetic

  • Slides: 42
Download presentation
Arithmetic, Logic Instructions and Programs Chapter 5

Arithmetic, Logic Instructions and Programs Chapter 5

Arithmetic Instructions

Arithmetic Instructions

ADDLW (ADD Literal to W) • Syntax: ADDLW k • Operation: (W) + k

ADDLW (ADD Literal to W) • Syntax: ADDLW k • Operation: (W) + k → W ▫ i. e: ADDLW 15 h

ADDWF (ADD W to f) • Syntax: ADDWF file. Reg, d • Operation: (W)

ADDWF (ADD W to f) • Syntax: ADDWF file. Reg, d • Operation: (W) + (f) → dest ▫ i. e: ADDWF REG, W

ADDWFC (ADD W and Carry bit to f) • Syntax: ADDWFC file. Reg, d

ADDWFC (ADD W and Carry bit to f) • Syntax: ADDWFC file. Reg, d • Operation: (W) + (f) + (C) → dest ▫ i. e: ADDWFC REG, W

Study Example 5 -3!

Study Example 5 -3!

Binary Coded Decimal (BCD) • Unpacked BDC ▫ 0000 1001 = 9 ▫ 0000

Binary Coded Decimal (BCD) • Unpacked BDC ▫ 0000 1001 = 9 ▫ 0000 0101 = 5 • Packed BCD ▫ 0101 1001 = 59 • Problem with adding packed BCD numbers, after adding the result is no longer BCD!

Binary Coded Decimal (BCD) (cont’d) i. e: movlw addlw 47 h 25 h •

Binary Coded Decimal (BCD) (cont’d) i. e: movlw addlw 47 h 25 h • BCD number: 0 – 9 • Solution? ? ? - DAW W = 47 h After: W = 6 Ch

DAW (Decimal Adjust W Register) • Syntax: DAW • Operation: DAW will add 6

DAW (Decimal Adjust W Register) • Syntax: DAW • Operation: DAW will add 6 to the nibbles when necessary • i. e: movlw 47 h addlw 25 h daw ; W = 47 h ; W = 6 Ch ; adjust BCD (W = 72 h)

Study Example 5 -4!

Study Example 5 -4!

SUBLW (Subtract W from Literal) • Syntax: SUBLW k • Operation: k – (W)

SUBLW (Subtract W from Literal) • Syntax: SUBLW k • Operation: k – (W) → W

SUBLW (Subtract W from Literal) (cont’d)

SUBLW (Subtract W from Literal) (cont’d)

SUBWFB (Subtract W from f with Borrow) • Syntax: SUBWFB file. Reg, d •

SUBWFB (Subtract W from f with Borrow) • Syntax: SUBWFB file. Reg, d • Operation: (f) – (W) – (C) → dest ▫ i. e: SUBWFB REG, F

SUBWFB (Subtract W from f with Borrow) (cont’d) ▫ i. e: SUBWFB REG, W

SUBWFB (Subtract W from f with Borrow) (cont’d) ▫ i. e: SUBWFB REG, W

SUBWFB (Subtract W from f with Borrow) (cont’d) ▫ i. e: SUBWFB REG, F

SUBWFB (Subtract W from f with Borrow) (cont’d) ▫ i. e: SUBWFB REG, F

SUBFWB (Subtract f from W with Borrow) • Syntax: SUBFWB file. Reg, d •

SUBFWB (Subtract f from W with Borrow) • Syntax: SUBFWB file. Reg, d • Operation: (W) – (f) – (C) → dest ▫ i. e: SUBFWB REG, F

SUBFWB (Subtract f from W with Borrow) (cont’d) ▫ i. e: SUBFWB REG, W

SUBFWB (Subtract f from W with Borrow) (cont’d) ▫ i. e: SUBFWB REG, W

SUBFWB (Subtract f from W with Borrow) (cont’d) ▫ i. e: SUBFWB REG, F

SUBFWB (Subtract f from W with Borrow) (cont’d) ▫ i. e: SUBFWB REG, F

MULLW (Multiply Literal with W) • Unsigned Number • Syntax: MULLW k • Operation:

MULLW (Multiply Literal with W) • Unsigned Number • Syntax: MULLW k • Operation: (W) x k → PRODH: PRODL

How about division of unsigned numbers? ? ? • Study Example 5 -8 &

How about division of unsigned numbers? ? ? • Study Example 5 -8 & Example 5 -9!

Signed Number

Signed Number

Signed 8 -bit Operands • Range of +ve number: 0 to +127 • Range

Signed 8 -bit Operands • Range of +ve number: 0 to +127 • Range of –ve number: -128 to 0

Study!!! • Workout Example 5 -10 to Example 5 -16 • When is the

Study!!! • Workout Example 5 -10 to Example 5 -16 • When is the OV flag set?

Logic and Compare Instructions

Logic and Compare Instructions

ANDLW (AND Literal with W) • Syntax: ANDLW k • Operation: (W). AND. k

ANDLW (AND Literal with W) • Syntax: ANDLW k • Operation: (W). AND. k → W

ANDWF (AND W with f) • Syntax: ANDWF file. Reg, d • Operation: (W).

ANDWF (AND W with f) • Syntax: ANDWF file. Reg, d • Operation: (W). AND. (f) → dest ▫ i. e: ANDWF REG, W

IORLW (Inclusive OR Literal with W) • Syntax: IORLW k • Operation: (W). OR.

IORLW (Inclusive OR Literal with W) • Syntax: IORLW k • Operation: (W). OR. k → W

IORWF (Inclusive OR W with f) • Syntax: IORWF file. Reg, d • Operation:

IORWF (Inclusive OR W with f) • Syntax: IORWF file. Reg, d • Operation: (W). OR. (f) → dest ▫ i. e: IORWF RESULT, W

XORLW (Exclusive OR Literal with W) • Syntax: XORLW k • Operation: (W). XOR.

XORLW (Exclusive OR Literal with W) • Syntax: XORLW k • Operation: (W). XOR. k → W

XORWF (Exclusive OR W with f) • Syntax: XORWF file. Reg, d • Operation:

XORWF (Exclusive OR W with f) • Syntax: XORWF file. Reg, d • Operation: (W). XOR. (f) → dest ▫ i. e: XORWF REG, F

COMF (Complement f) • Syntax: COMF file. Reg, d ▫ i. e: COMF REG,

COMF (Complement f) • Syntax: COMF file. Reg, d ▫ i. e: COMF REG, F

NEGF (Negate f) • Syntax: NEGF file. Reg ▫ i. e: NEGF REG ‘

NEGF (Negate f) • Syntax: NEGF file. Reg ▫ i. e: NEGF REG ‘ 58’ ‘- 58’ Taking 2’s complement of a number will result to its negative number! See Example 5 -22 for more detail

Compare Instructions No flag affected. Value file. Reg & Wreg remain unchanged!

Compare Instructions No flag affected. Value file. Reg & Wreg remain unchanged!

Study! • • • Example 5 -23 Example 5 -24 Example 5 -25 Example

Study! • • • Example 5 -23 Example 5 -24 Example 5 -25 Example 5 -26 Example 5 -27

Rotate Instruction & Data Serialization

Rotate Instruction & Data Serialization

RRNCF (rotate file. Reg right, no carry) • Syntax: RRNCF file. Reg, d ▫

RRNCF (rotate file. Reg right, no carry) • Syntax: RRNCF file. Reg, d ▫ i. e: RRNCF REG, F

RLNCF (rotate file. Reg left, no carry) • Syntax: RLNCF file. Reg, d ▫

RLNCF (rotate file. Reg left, no carry) • Syntax: RLNCF file. Reg, d ▫ i. e: RLNCF REG, F

RRCF (Rotate Right f through Carry) • Syntax: RRCF file. Reg, d ▫ i.

RRCF (Rotate Right f through Carry) • Syntax: RRCF file. Reg, d ▫ i. e: RRCF REG, W

RLCF (Rotate Left f through Carry) • Syntax: RLCF file. Reg, d ▫ i.

RLCF (Rotate Left f through Carry) • Syntax: RLCF file. Reg, d ▫ i. e: RLCF REG, W

Serializing a Byte of Data • Widely used in LCD, ADC and ROM •

Serializing a Byte of Data • Widely used in LCD, ADC and ROM • Study Example 5 -28, Example 5 -29 & Example 5 -30

SWAPF (swap f) • Syntax: SWAPF file. Reg, d ▫ i. e: SWAPF REG,

SWAPF (swap f) • Syntax: SWAPF file. Reg, d ▫ i. e: SWAPF REG, F

BCD & ASCII Conversion • Refer to Example 5 -32

BCD & ASCII Conversion • Refer to Example 5 -32