Searching \ for '[PIC] movlw Moves or Copies?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'movlw Moves or Copies?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] movlw Moves or Copies?'
2008\12\17@174837 by solarwind

picon face
If I do something like:

movlw 0x00

movwf TRISA
movwf TRISB
movwf TRISC

is it correct? Or do I need to movlw before every movwf?

--
..::[ solarwind ]::..

2008\12\17@180234 by Jan-Erik Soderholm

face picon face
solarwind wrote:

> If I do something like:
>
> movlw 0x00
>
> movwf TRISA
> movwf TRISB
> movwf TRISC
>
> is it correct?

Yes.
If you want the same value in all three.

2008\12\17@180846 by Jinx

face picon face
> If I do something like:
>
> movlw 0x00
>
> movwf TRISA
> movwf TRISB
> movwf TRISC
>
> is it correct? Or do I need to movlw before every movwf?

movwf doesn't change W. clrf TRISx would work in this example too

You can see what happens to registers in an editor Watch window

2008\12\17@181105 by olin piclist

face picon face
solarwind wrote:
> If I do something like:
>
> movlw 0x00
>
> movwf TRISA
> movwf TRISB
> movwf TRISC
>
> is it correct?

Given the comments explaining what it's supposed to do, sure.

> Or do I need to movlw before every movwf?

Your first instruction puts 0 in W, so the question is will the MOVWF
instructions change W or not.  Go to the data sheet and read the MOVWF
description.  Report back here on whether it changes W.

If your intent is to set the TRISx registers to 0, you can use CLRF.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2008\12\17@181638 by Jinx

face picon face
BTW, the example in the Instruction Descriptions of the 886 datasheet
is a great big hairy clue

Example: MOVWF OPTION

Before Instruction

OPTION = 0xFF
W = 0x4F

After Instruction

OPTION = 0x4F
W = 0x4F

Surely every programming language is similar and doesn't destroy source values

A = 10
B = A
C = A
D = A

2008\12\17@181747 by Harold Hallikainen

face
flavicon
face

> If I do something like:
>
> movlw 0x00
>
> movwf TRISA
> movwf TRISB
> movwf TRISC
>
> is it correct? Or do I need to movlw before every movwf?

That's fine. Watch your bank select bits, though. They call it "move", but
it is indeed copy. It does not delete the value from w. If it were to
delete it, what would it put there? The mov instruction is common to
pretty much every assembly language I'm familiar with. It indeed copies
the contents of one location to another (or in the case of movlw, copies
the literal into w).

Harold


--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

2008\12\17@182453 by Matthew Mucker

flavicon
face
This code is fine.

You're putting 0x00 in the w register, then copying it to TRISA, TRISB, and
TRISC.

As long as you don't execute any instruction that modifies w between these
instructions, you're fine. (The value of w won't change on its own.) Be
especially careful if you put a call statement in a sequence like this, as
the subroutine is likely to modify w.

The code snippet you posted is sound and correct and quite usable. An
alternate way to accomplish the same thing would be:

clrf TRISA
clrf TRISB
clrf TRISC

This not only saves you an instruction (which sometimes is important and
sometimes isn't), it also means you don't have to rely on the contents of
the w register. Preserving the value of w in an instruction sequence like
this is often useful, depending on what you have before and after the
sequence.  (In this particular case, clearing the TRIS registers, you're not
likely to have code before and after that needs to preserve w. But you might
have simiar code in other functional blocks where using clrf rather than
movlw 0x00 followed by movwf would come in handy.)

-----Original Message-----
From: spam_OUTpiclist-bouncesTakeThisOuTspammit.edu [.....piclist-bouncesKILLspamspam@spam@mit.edu] On Behalf Of
solarwind
Sent: Wednesday, December 17, 2008 4:48 PM
To: Microcontroller discussion list - Public.
Subject: [PIC] movlw Moves or Copies?

If I do something like:

movlw 0x00

movwf TRISA
movwf TRISB
movwf TRISC

is it correct? Or do I need to movlw before every movwf?

--
..::[ solarwind ]::..

2008\12\18@044909 by Alan B. Pearce

face picon face
>If I do something like:
>
>movlw 0x00
>
>movwf TRISA
>movwf TRISB
>movwf TRISC
>
>is it correct? Or do I need to movlw before every movwf?

It is correct. It is the ASM equivalent of the following C statement    

   TRISC = TRISB = TRISA = 0;

More... (looser matching)
- Last day of these posts
- In 2008 , 2009 only
- Today
- New search...