EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

W and WREG

Started by Eirik Karlsen February 7, 2004
Hi,
PIC18 and MPASM:
what is the thing about W and WREG ? Are those labels not 100% compatible?

The following lines:
SUBWF MCI,WREG
SUBWF LIMSTAT,WREG
ANDWF LIMPSTORE,WREG
all generate the compiler warning "Argument out of range. Least significant bits used."

But the following lines generates no warnings:
SUBWF MCI,W
SUBWF LIMSTAT,W
ANDWF LIMPSTORE,W I thought W and WREG interchangeable ....so what's the difference between 'em? --
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen



Don't know. W and WREG must be defined somewhere. Normally in the
.inc file. The ones I looked at only define W, and define it as
H'0000'. I think WREG must be defined for you somewhere as a larger
than 8 bit value to give that error.

As long as the constant evaluates to zero any label should work.

Chad

--- Eirik Karlsen <> wrote:
> Hi,
> PIC18 and MPASM:
> what is the thing about W and WREG ? Are those labels not 100%
> compatible?
>
> The following lines:
> SUBWF MCI,WREG
> SUBWF LIMSTAT,WREG
> ANDWF LIMPSTORE,WREG
> all generate the compiler warning "Argument out of range. Least
> significant bits used."
>
> But the following lines generates no warnings:
> SUBWF MCI,W
> SUBWF LIMSTAT,W
> ANDWF LIMPSTORE,W > I thought W and WREG interchangeable ....so what's the difference
> between 'em? > --
> *******************************************
> VISIT MY HOME PAGE:
> <http://home.online.no/~eikarlse/index.htm>
> LAST UPDATED: 23/08/2003
> *******************************************
> Best Regards
> Eirik Karlsen >


=====
My software has no bugs. Only undocumented features.

__________________________________



Hi Eirik,
WREG represents the 8-bit W register (the accumulator). W is an equate (alias) for a singe bit value of 0 and F is an equate (alias) for a single bit value of 1. W and F are used by certain instructions that operate on both the W register and another register to control whether the result is stored in the W registor or the other register. For example the encoding for
 
    ANDWF f, d
 
is 00 0101 d fff ffff
 
This ANDs the W register with register 'f'' If 'd' is 0 the result is stored in the W register. If 'd' is 1 the result is stored back in register 'f'.
 
The use of ,W or ,F is just to make the code more readable. You could writer ANDWF REG1, W also as ANDWF REF1, 0
 
You get the "argument out of range" error because in the 17F and 18F parts, the accumulator is at address $0A and Microchip's include files have the following:
 
WREG equ 0Ah
 
so when you write
 
    SUBWF MCI, WREG
 
your really writing
 
    SUBWF MCI, 0Ah
 
0Ah in binary is 00001010. Since the assembler truncates to the LSB and that is 0 in this case, its the same as writing
 
    SUBWF MCI, 0  or SUBWF MCI, W
 
so the net affect is what you wanted in the first place, albeit with the warning message. Better to be safe than sorry though so use W or F
 
Scott Kellish
SoftSystem Solutions
s...@comcast.net
----- Original Message -----
From: Eirik Karlsen
To: p...@yahoogroups.com
Sent: Saturday, February 07, 2004 1:44 PM
Subject: [piclist] W and WREG

Hi,
PIC18 and MPASM:
what is the thing about W and WREG ? Are those labels not 100% compatible?

The following lines:
SUBWF MCI,WREG
SUBWF LIMSTAT,WREG
ANDWF LIMPSTORE,WREG
all generate the compiler warning "Argument out of range.  Least significant bits used."

But the following lines generates no warnings:
SUBWF MCI,W
SUBWF LIMSTAT,W
ANDWF LIMPSTORE,WI thought W and WREG interchangeable ....so what's the difference between 'em?--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

----- Original Message -----
From: Eirik Karlsen <>
To: <>
Sent: Saturday, February 07, 2004 6:44 PM
Subject: [piclist] W and WREG > Hi,
> PIC18 and MPASM:
> what is the thing about W and WREG ? Are those labels not 100% compatible?
>
> The following lines:
> SUBWF MCI,WREG
> SUBWF LIMSTAT,WREG
> ANDWF LIMPSTORE,WREG
> all generate the compiler warning "Argument out of range. Least
significant bits used."
>
> But the following lines generates no warnings:
> SUBWF MCI,W
> SUBWF LIMSTAT,W
> ANDWF LIMPSTORE,W > I thought W and WREG interchangeable ....so what's the difference between
'em?

I haven't used the 18 series but from what I've read the W register is
mapped to a special function register as WREG. It allows you to perform
register only operations on W as though it were a RAM location e.g.

BTFSS WREG,3
or
RRF WREG

I looked this up in the 18 series docs and WREG is at address $FE8

Doing
ADDWF COUNT,WREG
would be like doing
ADDWF COUNT,FRED
i.e. trying to add two registers together

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising structured PIC BASIC compiler


Sorry,
WREG is in different locations in the 17F and 18F parts. Its at 0Ah in the 17F parts and FE8h in the 18F parts. Either way, the LSB is still 0
 
Scott
----- Original Message -----
From: Scott Kellish
To: p...@yahoogroups.com
Sent: Saturday, February 07, 2004 6:47 PM
Subject: Re: [piclist] W and WREG

Hi Eirik,
WREG represents the 8-bit W register (the accumulator). W is an equate (alias) for a singe bit value of 0 and F is an equate (alias) for a single bit value of 1. W and F are used by certain instructions that operate on both the W register and another register to control whether the result is stored in the W registor or the other register. For example the encoding for
 
    ANDWF f, d
 
is 00 0101 d fff ffff
 
This ANDs the W register with register 'f'' If 'd' is 0 the result is stored in the W register. If 'd' is 1 the result is stored back in register 'f'.
 
The use of ,W or ,F is just to make the code more readable. You could writer ANDWF REG1, W also as ANDWF REF1, 0
 
You get the "argument out of range" error because in the 17F and 18F parts, the accumulator is at address $0A and Microchip's include files have the following:
 
WREG equ 0Ah
 
so when you write
 
    SUBWF MCI, WREG
 
your really writing
 
    SUBWF MCI, 0Ah
 
0Ah in binary is 00001010. Since the assembler truncates to the LSB and that is 0 in this case, its the same as writing
 
    SUBWF MCI, 0  or SUBWF MCI, W
 
so the net affect is what you wanted in the first place, albeit with the warning message. Better to be safe than sorry though so use W or F
 
Scott Kellish
SoftSystem Solutions
s...@comcast.net
----- Original Message -----
From: Eirik Karlsen
To: p...@yahoogroups.com
Sent: Saturday, February 07, 2004 1:44 PM
Subject: [piclist] W and WREG

Hi,
PIC18 and MPASM:
what is the thing about W and WREG ? Are those labels not 100% compatible?

The following lines:
SUBWF MCI,WREG
SUBWF LIMSTAT,WREG
ANDWF LIMPSTORE,WREG
all generate the compiler warning "Argument out of range.  Least significant bits used."

But the following lines generates no warnings:
SUBWF MCI,W
SUBWF LIMSTAT,W
ANDWF LIMPSTORE,WI thought W and WREG interchangeable ....so what's the difference between 'em?--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions




The 2024 Embedded Online Conference