Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   



Logic Function Instructions

The next instructions set is the Logic Function instructions. Within this set, there are instructions to perform the typical logic functions such as OR, AND, XOR etc. Here is the list of them:

Instruction Description
ANDLW k Logic AND between the contents of W and the literal value k. The results is stored back to W.

ANDWF f , d Logic AND between the content of W register with the content of a file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'.

IORLW k Logic OR between the contents of W and the literal value k. The results is stored back to W.

IORWF f , d Logic OR between the content of W register from the content of a file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'.

XORLW k Logic EXCLUSIVE OR between the contents of W and the literal value k. The results is stored back to W.

XORWF f , d Logic EXCLUSIVE OR between the content of W register from the content of a file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'.

Now, let's see the instructions one by one:



ANDLW k

With this instructions you perform an AND logic function between the W register and the literal value k. The result is stored back to the W register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • W = W +.AND. f
    Where 0 <= k <= 255


Example
        movlw b'10000100'   ;The W register has now the binary value '10000100'
        andlw b'00001111'   ;The binary value '00001111' AND with the W register.
                            ;Now the W register has the binary value '00000100'



ANDWF f , d

With this instructions you perform an AND logic function between the W register and the file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • Destination (d) = W .AND. f
    Where 0 <= f <= 127


Example
;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
        movlw b'10000100'      ;The W register has the value '10000100'
        movwf TempRegister     ;The TempRegister has now the value '10000100'
        movlw d'00001111'      ;The W register has the value '00001111'
        andwf TempRegister,1   ;The W register AND with the contents of TempRegister 
                               ;and the result ('00000100') is stored to TempRegister



IORLW k

With this instructions you perform an OR logic function between the W register and the literal value k. The result is stored back to the W register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • W = W +.OR. f
    Where 0 <= k <= 255


Example
        movlw b'10000100'   ;The W register has now the binary value '10000100'
        iorlw d'00001111'   ;The binary value '00000011' OR with the W register.
                            ;Now the W register has the binary value '10001111'



IORWF f , d

With this instructions you perform an OR logic function between the W register and the file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • Destination (d) = W .OR. f
    Where 0 <= f <= 127


Example
;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
        movlw b'10000100'      ;The W register has the value '10000100'
        movwf TempRegister     ;The TempRegister has now the value '10000100'
        movlw d'00001111'      ;The W register has the value '00001111'
        iorwf TempRegister,1   ;The W register OR with the contents of TempRegister 
                               ;and the result ('10001111') is stored to TempRegister



XORLW k

With this instructions you perform an EXCLUSIVE OR logic function between the W register and the literal value k. The result is stored back to the W register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • W = W +.XOR. f
    Where 0 <= k <= 255


Example
        movlw b'10000100'   ;The W register has now the binary value '10000100'
        xorlw d'00001111'   ;The binary value '00000011' XOR with the W register.
                            ;Now the W register has the binary value '10001011'



XORWF f , d

With this instructions you perform an EXCLUSIVE OR logic function between the W register and the file register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register. The status affected from this function are:

  • Z - Zero

The logic operation performed is:

  • Destination (d) = W .XOR. f
    Where 0 <= f <= 127


Example
;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
        movlw b'10000100'      ;The W register has the value '10000100'
        movwf TempRegister     ;The TempRegister has now the value '10000100'
        movlw d'00001111'      ;The W register has the value '00001111'
        xorwf TempRegister,1   ;The W register OR with the contents of TempRegister 
                               ;and the result ('10001011') is stored to TempRegister



The Logic Functions Table

Here is a final tip for you. The following table demonstrates the result for the above functions between two bits.


Bit 1 Bit 2 AND OR XOR
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0






Confirm your knowledge

There is an online test to check your knowledge on this page. You may reveal the test with the following button:






Previous page ---- Next page



Go back to the book contents

Go to the discussion forum of this book





 

Comments

  Name

  Email (shall not be published)

  Website

Notify me of new posts via email


Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


      

  • At 23 February 2011, 20:06:32 user Kammenos wrote:   [reply @ Kammenos]
    • capn than you for the correction. I pressed 'd' instead of 'b'. 'd' stands for decimal but i declare a binary...


  • At 23 February 2011, 17:04:03 user capn wrote:   [reply @ capn]
    • I think you have a problem in your ANDlw code example.

      movlw b'10000100'
      andlw d'00001111' ;this should be b'00001111' should it not?

      because b'10000100' AND b'00001111' will give you b'00000100'.
     






    No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise without the prior written permission of the author.

    Read the Disclaimer


    All trademarks used are properties of their respective owners.
    Copyright © 2007-2009 Lazaridis Giorgos.
    All rights reserved.






     HOT in heaven!


  • Disclaimer
  • Book Contents
  • Discussion forum

  • Basics
  • What will you need
  • Choosing the right PIC
  • The MPLAB
  • Getting familiar with the MPLAB environment
  • Creating a new project
  • Open and close projects
  • Creating new files and including them in the project
  • Your very first assembly program
  • Compile a program and transfer to the PIC
  • Section 1: Beginner's theory
  • Memory Organization
  • The Data Memory Organization
  • The Program Memory Organization
  • The instructions
  • General knowledge about instructions
  • Value Loading Instructions
  • Program Flow Instructions
  • Mathematic Instructions
  • Logic Function Instructions
  • Bit Orientated Instructions
  • Byte Orientated Instructions
  • Miscellaneous Instructions
  • The Basic Special Function Registers
  • The Status Register
  • The Option_Reg Register
  • The TRIS and PORT registers
  • Beginner's PIC Tutorials
  • How to use our PIC Tutorials
  • A Pushbutton turning an LED on and off
  • A Simple LED Flasher
  • Interfacing Multiple Switches - The internal Pull-Up resistors
  • An LED Sequencer
  • Interface a Single 7seg Digit
  • Interface Multiple 7seg Digits
  • A 3-digits Decimal Counter
  • A Clever Button
  • Section 2: Intermediate theory
  • Instruction Cycle Duration and Calculated Delays
  • The Timer Modules - Timer0
  • The Timer Modules - Timer1
  • The Timer Modules-Timer2



  • NEW in heaven!



    New Theory: AC electric motor working principle






     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy