Академический Документы
Профессиональный Документы
Культура Документы
• any data larger than 8 bits must be broken into 8-bit chunks
before it is processed.
• WREG stands for working register, as there is only one.
• The WREG register is used for all arithmetic and logic
instructions.
• ADDLW
ADDLW K ;ADD literal value K to WREG
▫ The ADD instruction tells the CPU to add the literal value K to register
WREG and put the result back in the WREG register.
MOVLW 25H ;load 25H into WREG
ADDLW 34H ;add value 34 to W (W = W + 34H)
Gaby Abou Haidar M.S. Fall 2017 - 2018
Gaby Abou Haidar M.S. Fall 2017 - 2018
• Example:
MOVLW 12H ;load value 12H into WREG (WREG = 12H)
ADDLW 16H ;add 16 to WREG (WREG 28H)
ADDLW 11H ;add 11 to WREG (WREG 39H)
ADDLW 43H ;add 43 to WREG (WREG 7CH)
• Example:
MOVLW 7F2H ;ILLEGAL 7F2H > 8 bits, becomes F2H
MOVLW 456H ;ILLEGAL 456H > FFH, becomes 56H
MOVLW 60A5H ;ILLEGAL but becomes ASH
▫ The d bit selects the destination for the operation. If d = w; the result is
stored in WREG (d = 0). If d = F; the result is stored in the fileReg (d =1 ).
The default is F.
Gaby Abou Haidar M.S. Fall 2017 - 2018
• Instruction
▫ COMF fileReg, d ;Complement fileReg
▫ DECF fileReg, d ;Decrement fileReg
▫ DECFSZ fileReg, d ;Decrement file Reg and skip if zero
▫ DECFSNZ fileReg, d ;Decrement fileReg and skip if not zero
▫ INCF fileReg, d ;Increment fileReg
▫ INCFSZ fileReg, d ;Increment fileReg and skip if zero
▫ INCSNZ fileReg, d ;Increment fileReg and skip if not zero
▫ MOVF fileReg, d ;Move fileReg
▫ NEGF fileReg, d ;Negative fileReg
▫ RLCF fileReg, d ;Rotate left fileReg through carry
▫ RLNCF fileReg, d ;Rotate left fileR eg (No carry)
▫ RRCF fileReg, d ;Rotate right fileReg through carry
▫ RRNCF fileReg, d ;Rotate right fileReg (No carry)
▫ SWAPP fileReg, d ;Swap nibbles in fileReg
▫ BTG fileReg, d
Gaby Abou Haidar M.S.
;Bit Toggle fileReg
Fall 2017 - 2018
• COMF
▫ complements (inverts) the contents of fileReg and places the result in
WREG or fileReg.
MOVLW 55H ;WREG = 55h
MOVWF PORTE ;Move WREG to Port B SFR (PB= 55h)
COMF PORTE, F ;complement Port B (PB= AAh)
• DECF
▫ decrements the contents of fileReg, the result in WREG or fileReg.
MOVLW 3 ;WREG = 3
MOVWF 20H ;move WREG to loc 20H (loc 20H = 3)
DECF 0x20, F ;loc 20H has 2
DECF 0x20, F ;loc 20H has 1
DECF 0x20, F ;loc 20H has 0 and WREG = 3
Gaby Abou Haidar M.S. Fall 2017 - 2018
• MOVF
MOVF fileReg, D
▫ If D = 0, it copies the content of fileReg to WREG.
▫ If D = 1, the content of fileReg is copied to itself.
▫ we use the MOVF instruction to bring data into WREG from I/0 pins
▫ we sometimes use it to copy fileReg to itself for the purpose of testing
fileReg contents.
▫ the MOVF instruction is used to bring data from I/0 ports e.g. Port B into
the CPU.
▫ We also use the MOVF instruction to bring data into WREG from any
SFRs or from any location in the GP RAM in order to perform arithmetic
and operations on them.
• Example: Write a program to get data from the SFRs of Port B. Add
the value 5 to it and send it to the SFRs of Port C.
MOVF PORTB,W ;bring data from Port B into WREG
ADDLW 05H ;add 5 to WREG
MOVWF PORTC ;copy WREG to Port C
• Setting the LSB of the target address to zero will make sure that the
target address is an even address. As we saw in the last section, that is
exactly what we want because all the instructions are either 2-byte or
4-byte.