| ||
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:
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:
The logic operation performed is:
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:
The logic operation performed is:
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:
The logic operation performed is:
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:
The logic operation performed is:
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:
The logic operation performed is:
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:
The logic operation performed is:
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.
Confirm your knowledge There is an online test to check your knowledge on this page. You may reveal the test with the following button: Comments
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. |
|
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 |