Searching \ for 'sublw' 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/index.htm?key=sublw
Search entire site for: 'sublw'.

No exact or substring matches. trying for part
PICList Thread
'sublw opcode & blown up PIC'
1997\11\20@063503 by David BALDWIN

flavicon
face
Hi everybody,

       I was away for a while, but I am now back. Don't matter, nobody knew
me...:(
       I am back because I need your help. I have an ASM file that contains:

       sublw   .3

and it is not working properly. When I am replacing it with addlw 0xFD,
everything is working! I though the assembler was translating a sublw
into the right addlw?! Is it the same opcode?

Another BIG problem:

       I am reading a byte 0xAD in EEPROM, with:

EEREAD  bsf     STATUS,RP0
       bsf     EECON1,RD
       bcf     STATUS,RP0
       movf    EEDATA,w
       return


In my main program I am doing the following code:

       call    EEREAD
       btfsc   w,2
       goto    OK
       ....
OK      "Send to LCD that I have been here"

The problem is that I never go to OK!!! BUT when doing the following:

       call    EEREAD
       btfsc   EEREAD,2
       goto    OK
       ....
OK      "Send to LCD that I have been here"

       Everithing is working! I really don't understand what's happening!
Please ... help me.


David

1997\11\20@081147 by Dmitry Kiryashov

flavicon
face
Hello David .

> Hi everybody,
> I was away for a while, but I am now back. Don't matter, nobody knew me...:(
Don't cry i remember you. ;)

>         I am back because I need your help. I have an ASM file that contains:
>
>         sublw   .3
>
> and it is not working properly. When I am replacing it with addlw 0xFD,
> everything is working! I though the assembler was translating a sublw
> into the right addlw?! Is it the same opcode?

David, look carefully in your PIC manual. I think you will be surprised
because sublw K mean K-W result to W not W-K as you think !
But addlw -K works as you expect: W-K result to W .
It's the Greate Microchip joke . ;)))

WBR Dmitry.

1997\11\20@103213 by myke predko

flavicon
face
Hi Dave,

>        I was away for a while, but I am now back. Don't matter, nobody knew
>me...:(

We're glad you're back anyways...

>        I am back because I need your help. I have an ASM file that contains:
>
>        sublw   .3
>
>and it is not working properly. When I am replacing it with addlw 0xFD,
>everything is working! I though the assembler was translating a sublw
>into the right addlw?! Is it the same opcode?

Dmitry answered your question.

{Quote hidden}

The problem is, you aren't "btfsc w,2" - you are actually executing:

 btfsc INDF, 2

"w" is evaluated to Zero in MPASM and Register Zero is actually "INDF" (the
register pointed to by FSR.

In this case, you can either use the working code exchange:

 btfsc w,2

with

 andlw 4                       ;  Isolate Bit 2
 btfss STATUS, Z

But, I would stick with the working example (not only is it easier to
understand, but it doesn't change the value in "w").


Good luck,

myke

PICList Etiquette at:

http://www.myke.com/piclist

1997\11\20@104307 by Bob Fehrenbach

picon face
David BALDWIN <spam_OUTdbTakeThisOuTspamSDM.BEL.ALCATEL.BE> wrote:
>        sublw   .3
>
>and it is not working properly. When I am replacing it with addlw 0xFD,
>everything is working! I though the assembler was translating a sublw
>into the right addlw?! Is it the same opcode?

  sublw .3      does:  3 - w
  addlw h'fd'   does:  h'fd' + w  =  - 3  +  w  =  w - 3

  BTW this is a very handy trick to reverse the subtraction order.


>
>        call    EEREAD
>        btfsc   w,2       <- Illegal.  Can't test bits in w.
>        goto    OK           This is actually testing the register
                             pointed to by the FSR register


>        call    EEREAD
>        btfsc   EEREAD,2  <- ??  EEREAD is a label in your program.
>        goto    OK           The register actually being tested
                             depends on the address of EEREAD.


--
Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam@spam@execpc.com

1997\11\20@122112 by Mike Keitz
picon face
On Thu, 20 Nov 1997 12:28:25 +0100 David BALDWIN <dbspamKILLspamSDM.BEL.ALCATEL.BE>
writes:

>        I am back because I need your help. I have an ASM file that
>contains:
>
>        sublw   .3
>
>and it is not working properly. When I am replacing it with addlw
>0xFD,
>everything is working! I though the assembler was translating a sublw
>into the right addlw?! Is it the same opcode?

No they are not equivalent.
sublw computes W = L - W
addlw computes W = L + W
They have different opcodes, and different uses.  sublw negates W in the
process, addlw doesn't.  If you use addlw with a negative literal
(constant) to effect a subtraction, the result is W - L.

>        I am reading a byte 0xAD in EEPROM, with:
>
>EEREAD  bsf     STATUS,RP0
>        bsf     EECON1,RD
>        bcf     STATUS,RP0
>        movf    EEDATA,w
>        return
>

Before using this routine, you have to store the EEPROM address of the
byte to be read in the EEADR special register.  I don't think EEADR is
set to any particular known value after a reset.

There are only 64 bytes of EEPROM, so EEADR must be set within 0x00 to
0x3F.  Attempting to use illegal EEPROM addresses will read 0 (and
increase the power consumption somewhat, according to the F84 data).

>
>In my main program I am doing the following code:
>
>        call    EEREAD
>        btfsc   w,2
>        goto    OK
>        ....
>OK      "Send to LCD that I have been here"

Except on the PIC17CXX, the btfsc instruction can't work on W.  (w and f
are predefined to 0 and 1 to use as indications for the instructions that
accept either destination, thus this doens;t generate an error.  I don't
like this very much, I would rather have the assembler parse these
instructions looking for either 0,1, or a letter explicitly).

Anyway to test a bit in W, you can do a logical AND instruction to
isolate the bit, then test the Z flag.  But this zeros the other bits in
W.  Another way is to store the value to RAM, then use a btfs instruction
on the bit.
If EEADR is beyond 0x3F, then the chip will read zero, and the skip will
always skip.

>
>The problem is that I never go to OK!!! BUT when doing the following:
>
>        call    EEREAD
>        btfsc   EEREAD,2
>        goto    OK
>        ....

This, though technically legal, is programming gibberish.  The assembler
defines EEREAD as the address of your EEREAD routine in ROM.  Trying to
use it as an address in RAM will have unpredictable results.

1997\11\21@200702 by Alex I. Torres

flavicon
face
Hi All!

m>  I have an ASM file that contains:
m>
m>         sublw   .3
m>
m> and it is not working properly.

What do you want ?   W-3 ? It's wrong! sublw .3 means W=3-W

m> When I am replacing it with addlw 0xFD, everything is working!

Of course! 0xFD = .-3,  and  addlw 0xFD == W-3

m> Another BIG problem:
m>
m>         I am reading a byte 0xAD in EEPROM, with:
m>
m> EEREAD  bsf     STATUS,RP0
m>         bsf     EECON1,RD
m>         bcf     STATUS,RP0
m>         movf    EEDATA,w
m>         return
m>
m>
m> In my main program I am doing the following code:
m>
m>         call    EEREAD
m>         btfsc   w,2
m>         goto    OK
m>         ....

m> The problem is that I never go to OK!!! BUT when doing the
m> following:
m>
m>         call    EEREAD
m>         btfsc   EEREAD,2
m>         goto    OK
m>         ....
m> OK      "Send to LCD that I have been here"
m>
m>         Everithing is working! I really don't understand
m> what's happening! Please ... help me.

It's very simple :-)

When you write  "btfss W,2" it's the same, as "btfsc 0,2" - you
test the 2nd bit of register, which address=0 - it is INDF, so
you test the 2nd bit of register, which address is in FSR.

  Alex Torres, .....altorKILLspamspam.....cook.kharkov.ua
  Kharkov,Ukraine

--- GoldED 2.50.A0531+


'[PIC]: addlw -(.10+1) versus sublw .11'
2002\01\10@120408 by Simon-Thijs=20de=20Feber?=
flavicon
face
Hello all,

I have found the following piece of code which is
included in a delay routine (delay X cycles (11-256)
by Regulus Berdin ) :

addlw -(.10+1)
addlw -4

can i replace it with

sublw .11
sublw .4

cause as written literally the compiler did no accept
it !


grtz

Simon



__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2002\01\10@131712 by Andrew Warren

flavicon
face
Simon-Thijs de Feber <PICLISTspamspam_OUTmitvma.mit.edu> wrote:

> addlw -(.10+1)
> addlw -4
>
> can i replace it with
>
> sublw .11
> sublw .4

Simon:

No, you can't do that.  "ADDLW -11" subtracts 11 from W; "SUBLW 11"
subtracts W from 11.

Instead, you can replace it with:

   addlw .256-(.10+1)    ; or addlw 245
   addlw .256-.4         ; or addlw 252

-Andy

=== Andrew Warren -- @spam@aiwKILLspamspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\10@150528 by Simon-Thijs=20de=20Feber?=

flavicon
face
Hello,

OK i understand.
But somehow CC5x does not accept the following inline
assembly :

addlw -(.10+1)

This it accepts :

addlw .256 - 11

Why it did not accept the firts line of assembly.


grtz

Simon


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\11@042326 by Dag Bakken

flavicon
face
I must admit ... I've never tried that, but I ran your problem through
CC5X, and found two distingt problems.  Minus and parentheses.
This is not accepted: addlw -11
This is accepted:     addlw 0-11
This is not accepted: addlw (-11)
This is not accepted: addlw (0-11)

It won't take parentheses at all, and it looks like it won't evaluate
immediate negative numbers.

On the other hand, CC5X will generate the same code in assembler if
you do this in C:
   W+=-11;

Dag S

STdF> Hello,

STdF> OK i understand.
STdF> But somehow CC5x does not accept the following inline
STdF> assembly :

STdF> addlw -(.10+1)

STdF> This it accepts :

STdF> addlw .256 - 11

STdF> Why it did not accept the firts line of assembly.


STdF> grtz

STdF> Simon


STdF> __________________________________________________
STdF> Do You Yahoo!?
STdF> Everything you'll ever need on one web page
STdF> from News and Sport to Email and Music Charts
STdF> http://uk.my.yahoo.com

STdF> --
STdF> http://www.piclist.com#nomail Going offline? Don't AutoReply us!
STdF> email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu



'[PIC]: SUBLW'
2002\05\15@184611 by Thomas C. Sefranek
face picon face
Burned!!!

SUBLW does NOT SUBtract Literal from W!
(It subtracts W from Literal)

WHY did they reverse the order of the operands in the Mnemonic?


 *
 |  __O    Thomas C. Sefranek  RemoveMEtcsspamTakeThisOuTcmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

ARRL Instructor, Technical Specialist, VE Contact.
hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2002\05\15@191942 by M. Adam Davis

flavicon
face
Every year or so someone is burned by it.  There is an obscure reason,
but it escapes me at the moment - hope it didn't kill too much of your time!

-Adam

Thomas C. Sefranek wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2002\05\16@024905 by Dmitriy A. Kiryashov

picon face
Hi Thomas.

Just to let you simply have another choice to do:

addlw   -const


WBR Dmitry.


>"Thomas C. Sefranek" wrote:
>
> Burned!!!
>
> SUBLW does NOT SUBtract Literal from W!
> (It subtracts W from Literal)
>
> WHY did they reverse the order of the operands in the Mnemonic?

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspamspammitvma.mit.edu


2002\05\16@091113 by Eoin Ross

flavicon
face
Its not really reversed ...

SUBLW ...  L - W = result

>>> EraseMEadampicspamspamspamBeGoneUBASICS.COM 05/15/02 07:17PM >>>
Every year or so someone is burned by it.  There is an obscure reason,
but it escapes me at the moment - hope it didn't kill too much of your time!

-Adam

Thomas C. Sefranek wrote:
>SUBLW does NOT SUBtract Literal from W!
>(It subtracts W from Literal)
>WHY did they reverse the order of the operands in the Mnemonic?
>  |  __O    Thomas C. Sefranek  RemoveMEtcsKILLspamspamcmcorp.com
--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestSTOPspamspamspam_OUTmitvma.mit.edu


2002\05\16@093303 by Alan B. Pearce

face picon face
>Its not really reversed ...

>SUBLW ...  L - W = result

Well it is reversed compared to the SUBWF mnemonic which is F - W = result,
and that is why people get confused.

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestSTOPspamspamEraseMEmitvma.mit.edu


2002\05\16@093650 by Douglas Wood

picon face
Most micros use the "register minus literal" method...

Douglas Wood
Software Engineer
KILLspamdbwoodspamBeGonespamkc.rr.com

Home of the EPICIS Development System for the PIC and SX
http://epicis.piclist.com

{Original Message removed}

2002\05\16@103233 by Bob Ammerman

picon face
----- Original Message -----
From: "Douglas Wood" <EraseMEdbwoodspamEraseMEKC.RR.COM>
To: <@spam@PICLIST@spam@spamspam_OUTMITVMA.MIT.EDU>
Sent: Thursday, May 16, 2002 9:31 AM
Subject: Re: [PIC]: SUBLW


> Most micros use the "register minus literal" method...

But why waste the opcode space when you can just use "register
plus -(literal) instead".

Actually, I have found sublw to be very useful on several occasions.

Bob Ammerman
RAm Systems

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2002\05\16@121853 by Dwayne Reid

flavicon
face
At 10:23 AM 5/16/02 -0400, Bob Ammerman wrote:

>But why waste the opcode space when you can just use "register
>plus -(literal) instead".

Note that ADDLW and SUBLW don't exist in the 12 bit core parts.  I have to
be careful when porting existing code written for the 14 bit parts over to
the 12 bit family.

dwayne


Dwayne Reid   <.....dwaynerspam_OUTspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-request.....spamTakeThisOuTmitvma.mit.edu


2002\05\17@005329 by Tal Dayan

flavicon
face
My 2c is that they wanted to provide us one more option:

w = w - K  ==>    addlw   -K

w = k - w  ==>    sublw    K     // also  w = -w ==>  sublw  0

Otherwise, sublw would be practically redundant.

Does this makes sense ?

Tal

> {Original Message removed}

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