Arithmetic Logic Instructions and Programs Chapter 5 Arithmetic
- Slides: 42
Arithmetic, Logic Instructions and Programs Chapter 5
Arithmetic Instructions
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) + (f) → dest ▫ i. e: ADDWF REG, W
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!
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 • 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 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!
SUBLW (Subtract W from Literal) • Syntax: SUBLW k • Operation: k – (W) → W
SUBLW (Subtract W from Literal) (cont’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, F
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, F
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 & Example 5 -9!
Signed Number
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 OV flag set?
Logic and Compare Instructions
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). AND. (f) → dest ▫ i. e: ANDWF REG, W
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: (W). OR. (f) → dest ▫ i. e: IORWF RESULT, W
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: (W). XOR. (f) → dest ▫ i. e: XORWF REG, F
COMF (Complement f) • Syntax: COMF file. Reg, d ▫ i. e: COMF REG, F
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!
Study! • • • Example 5 -23 Example 5 -24 Example 5 -25 Example 5 -26 Example 5 -27
Rotate Instruction & Data Serialization
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 ▫ i. e: RLNCF REG, F
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. e: RLCF REG, W
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, F
BCD & ASCII Conversion • Refer to Example 5 -32
- Cpmcd in software engineering
- Cmpb assembly
- Microprogrammed control
- The objective of sharpening spatial filter is to
- Control unit
- Arithmetic logic unit
- First order logic vs propositional logic
- First order logic vs propositional logic
- Third order logic
- Combinational vs sequential logic
- Tw
- Software development plan
- Majority circuit
- Combinational logic sequential logic 차이
- Logic chapter 3
- Types of early childhood programs chapter 2
- Creative thinking
- Inductive generalization
- Language proof and logic solutions chapter 11
- Logic chapter 3
- Logic chapter four
- 2-to-1 multiplexer
- Logic chapter 3
- Logic chapter 6
- Arithmetic and geometric sequences and series
- Ramon magsaysay contribution
- National health intervention program for mother and child
- Monitoring and evaluation of family planning programs
- Programmers use backdoors to debug and test programs.
- Designing effective hrd programs
- Site:slidetodoc.com
- Developing pricing strategies and programs
- Dual language immersion programs pros cons
- Ppc seo and affiliate programs
- Designing and managing incentive compensation programs
- Dash is collection of interrelated data
- Operating system utility programs
- Objectives of an operating system
- Programs that organize analyze and graph numerical data
- Designing and implementing brand architecture strategies
- Small pictures that represent files folders and programs
- Designing and implementing brand marketing programs
- Blue and gold basics sae programs