---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id ABD336F50068; Sun, 01 Feb 2004 12:04:35 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <16.00CC7F8C@cherry.ease.lsoft.com>; 1 Feb 2004 15:04:30 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 2488 for PICLIST@MITVMA.MIT.EDU; Sun, 1 Feb 2004 15:04:24 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 3084; Sun, 1 Feb 2004 15:02:44 -0500 Received: from extsmtp1.localnet.com [207.251.201.54] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with SMTP ; Sun, 01 Feb 2004 15:02:44 EST X-Comment: mitvma.mit.edu: Mail was sent by extsmtp1.localnet.com Received: (qmail 27964 invoked from network); 1 Feb 2004 19:28:40 -0000 Received: from thwerll.localnet.sys (HELO smtp1.localnet.com) (10.0.7.18) by extsmtp1.localnet.com with SMTP; 1 Feb 2004 19:28:40 -0000 Received: (qmail 20868 invoked from network); 1 Feb 2004 20:02:45 -0000 Received: from unknown (HELO kmp) (66.155.244.76) by smtp3.localnet.com with SMTP; 1 Feb 2004 20:02:45 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal Message-ID: Date: Sun, 1 Feb 2004 15:02:51 -0500 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: Ken Pergola Subject: Re: [PIC:] AND, and OR To: PICLIST@MITVMA.MIT.EDU In-Reply-To: Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856768 Ruben Undheim wrote > Without understanding this, I don't see what use I can get from the > ANDLW, ANDWF, IORWF, XORWF, IORLW, XORLW-commands. Hi Ruben, Let me answer some of your whys: Ruben, you'll love the power of the beautiful instructions! I'll just describe a few examples, but you should get the idea. There are many uses for these instruction, so please do not infer that my examples are the only ways these instructions can be used. Normally you don't want to hard-code constants as I have shown (sometimes referred to as magic numbers), but I did this for clarity reasons for you. Also, remember that 'bit x' is zero-based: bit 0 refers to the least significant bit in a byte. ANDLW: ------ Let's assume you are implementing defensive programming techniques and you have a sub/function that *absolutely must* take an argument in the 0 to 7 (decimal range) in the W register (8-bit). An 8-bit register can take on the values of 0 to 255 (decimal), so how can you prevent a user from passing anything greater that 7 in the W register? You can't, but you can use the ANDLW instruction in the function to coerce the passed W register argument into the range that your sub/function requires: YourFunction ; Input(s): ; W register (must be 0 to 7) ANDLW .7 ; Coerce W register argument into the desired range of 0-7 . . . ANDWF: ------ Problem: You want to zero bit 8 of a file register without affecting the other bits in the file register: (A vending machine with 8 different products) ; Release the Twinkies for the customer MOVLW B'01111111' ANDWF VendingMachineProducts, F CALL DropTheProductIntoBin IORWF: ------ Problem: You want to set bit 3 of a file register without affecting the other bits in the file register: ; Fire the spark plug in cylinder #4 MOVLW B'00001000' IORWF Cylinders, F CALL RefreshCylinders XORWF: ------ One example: perform an equality test: MOVLW ENGINE_KNOCK_ERROR_CODE XORWF EngineStatus, W BZ DisplayErrorOnDashBoard ; Display error to user ; If code flows here, there wasn't any engine knock problem . . . Hopefully these examples will help give you some understanding of the uses of these powerful instructions you had questions about. Take care Ruben, Ken Pergola -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads .