Hot!addwf doesn't set carry ?

Page: 12 > Showing page 1 of 2
Author
AleMala
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2018/10/07 15:30:17
  • Location: 0
  • Status: offline
2018/10/09 16:46:43 (permalink)
0

addwf doesn't set carry ?

I am using MPLABX v 5.00 emulator and i had to use different instructions couse
the following code doesn't work:
      
     MOVIW INDF0++
     ADDWF INDF0,W
     RRF WREG,W

the problem is the second (ADDWF)  that doesn't change the carry flag ?
Help welcome! Alessandro.
#1

21 Replies Related Threads

    GeorgePauley
    Moderator
    • Total Posts : 1019
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/10 08:33:08 (permalink)
    +2 (2)
    What device
    #2
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/10 15:56:51 (permalink)
    0
    MPLABX v 5.00 emulator for pic16f1459.
    #3
    qhb
    Superb Member
    • Total Posts : 7891
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Flagged as Spam (1)
    Re: addwf doesn't set carry ? 2018/10/10 16:18:09 (permalink)
    0 (2)
    MPLABX 5.05 has been out for a while now.
     
    #4
    GeorgePauley
    Moderator
    • Total Posts : 1019
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/11 11:09:32 (permalink)
    +3 (3)
    I just ran this and saw the carry flag set.  Are you sure the input values to the ADDWF are what you think they are?
     
        MOVLW 0x00
        MOVWF FSR0H
        MOVLW 0x65
        MOVWF FSR0L
        MOVLW 0xFF
        MOVWF 0x65
        ADDWF INDF0,W
     
    #5
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/11 16:29:17 (permalink)
    0
    I try your code and it sets the carry properly !
    I will install the new version 5.05 and check.
    Regards, Alessandro
    #6
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/13 13:22:47 (permalink)
    0
    You are right, I try this code and everything works fine.
    MOVLW 0x00
    MOVWF FSR0H
    MOVLW 0x65
    MOVWF FSR0L
    MOVLW 0x1
    MOVWF 0x65
    MOVWF 0x66
    BSF STATUS,0
    MOVIW INDF0++
    ADDWF INDF0,W

    By the way, i remember now that after some errors i installed a newer underlying java machine.
    But the most affordable option may be i was drunk !!!
    Excuse me, Alessandro.
    #7
    GeorgePauley
    Moderator
    • Total Posts : 1019
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/17 08:31:01 (permalink)
    +1 (1)
    FYI:  MPLAB X installs and uses its own "private" installation of Java.  So you can update Java on your machine without having to worry about affecting MPLAB X.
    #8
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/17 14:08:25 (permalink)
    0
    The java machine updated automatically by installing the MLA library.
    I think i have been able to catch an error.
    Here attached are the disassembly and trace instructions ?
    Attachments are not available: Download requirements not met Attachments are not available: Download requirements not met
     
    Alessandro.

    Attachment(s)

    Attachments are not available: Download requirements not met
    #9
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/17 15:48:19 (permalink)
    0
    Here is a screenshot !

    Attachment(s)

    Attachments are not available: Download requirements not met
    #10
    dan1138
    Super Member
    • Total Posts : 2897
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/17 19:59:24 (permalink)
    0
    With MPLABX v4.05 I used this code:

    ; PIC16F1459 Configuration Bit Settings

    #include "p16f1459.inc"

    ; CONFIG1
    ; __config 0xC9E4
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    ; CONFIG2
    ; __config 0xDFFF
     __CONFIG _CONFIG2, _WRT_OFF & _CPUDIV_CLKDIV6 & _USBLSCLK_48MHz & _PLLMULT_3x & _PLLEN_ENABLED & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF

    RES_VECT  CODE  0x0000
        GOTO    START

    MAIN_CONST CODE 0x0004
    Table   DW  0x000A
            DW  0x0014

    MAIN_DATA UDATA 0x3E
    pippo   res 1

    MAIN_PROG CODE  0x100

    START
        MOVLW   HIGH(Table)
        MOVWF   FSR0H
        MOVLW   LOW(Table)
        MOVWF   FSR0L
        banksel pippo
        clrf    pippo
        pagesel 0xD44
        CALL    0xD44
        nop

        GOTO    $

    F1_CODE CODE    0xD44

        MOVIW   FSR0++
        MOVWF   pippo
        ADDWF   INDF0, W
        RRF     WREG, W
        RETURN

        END

    To produce this simulator trace output:

    Line    Address      Op     Label     Instruction          SA    SD    DA    DD       Cycles
     -8     0108         0000             NOP                 ----   --   ----   --   0000000010
     -7     0D44         0012             MOVIW FSR0++        ----   --   ----   --   0000000011
     -6     0D45         0000             NOP                 ----   --   ----   --   0000000012
     -5     0D45         00BE             MOVWF pippo         ----   --   pippo  0A   0000000013
     -4     0D46         0700             ADDWF INDF0, W      8005   14   W      1E   0000000014
     -3     0D47         0000             NOP                 8005   14   W      1E   0000000015
     -2     0D47         0C09             RRF WREG, W         W      --   W      0F   0000000016
     -1     0D48         0008             RETURN              ----   --   ----   --   0000000017

    It looks like you have found an issue were the MPLABX v5.00 simulator is finding the CARRY set after an ADD of 0x0A with 0x14.

    Can anyone else reproduce AleMala results with my sample code?

    GeorgePauley,
    Could you comment as to how the MPLABX v5.00 simulator can do what AleMala is seeing?
    #11
    GeorgePauley
    Moderator
    • Total Posts : 1019
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/18 14:14:01 (permalink)
    0
    I run this code in MPLAB X 5.00, 5.05 and the current trunk (5.10) and do NOT see the carry flag set when I execute the ADDWF instruction!  sad: sad
    #12
    dan1138
    Super Member
    • Total Posts : 2897
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/18 14:38:38 (permalink)
    0
    George,
     
    Is there anything about the core simulator implementation that has any dependency on the version of Java run time environment, type of CPU or operating system it runs on?
     
    Intel vs AMD, 64-bit vs 32-bit, JRE 7.xx vs JRE8.xx?
     
    Have you heard of any sensitivity to anti-virus tools with the simulator?
     
    It seems that the issue that AleMala is seeing may be specific to the MPLABX installation.
     
    I fully understand that there is nothing that Microchip can do to resolve this until a stable reproduction method can be submitted. I'm just trying to narrow the scope of how to look for one.
    #13
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/18 16:32:07 (permalink)
    0
    I was in trouble about posting but at the end decided to inform you.
    Everything can be ! i have a small pc with less than minimum memory.
    i always connect everywhere to internet. Everything can be !
    Suppose a virus on it !!!
    I don't work by now and for me it's an hobby !
    http://alemala.xoom.it/alemala/bodies/BrushLess/twin_brushless.htm
    The code is part of a math library i developed. The multiply and division
    according to me are faster than all those i have seen.
    The only option would be to post all my source code to allow you some check.
    I don't like it so much, my dream would be to sell some code before die !!!!!!
    But i know it will never happen !!!!
     
    Thanks. Alessandro
     
    #14
    dan1138
    Super Member
    • Total Posts : 2897
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/18 20:56:49 (permalink)
    +1 (1)
    Alessandro,
     
    It is clear enough to me that your code is provoking a fault with the MPLABX v5.00 simulator.
     
    The screen shot of the simulation instruction trace shows the the WREG has the value 0x0A the ADD source operand is fetched indirectly from FSR0 from program space address 0x0005 and has the vale 0x14. After the ADDWF instruction the WREG hold the value of 0x1E.
     
    Then the RRF WREG,W instruction executes and result in WREG is 0x8F.
     
    For the sequence of instruction shown in the simulation trace this is an invalid result.
     
    This must be a fault in the simulator but I have been unable to reproduce the results you are seeing.
     
    Please describe how your workstation is setup:
    • Is it 64-bit or 32-bit MacOS, Linux or Windows?
    • How much real memory?
    • Exactly what kind of antivirus software?
    Also please do not post your code here. If you can create a stable way to reproduce the fault then contact the Microchip technical support. Then open a support case. There you can show them your code without posting it on a public forum.
    #15
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/19 05:43:14 (permalink)
    0
    I isolated some code, but it is not possible to post it on the forum,
    I will try your suggestion to contact Microchip technical support.
    Thanks a lot, Alessandro
     
    #16
    Jim Nickerson
    User 452
    • Total Posts : 5578
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/19 05:45:06 (permalink)
    +1 (1)
    Maybe you could try the code on a real chip ?
    #17
    GeorgePauley
    Moderator
    • Total Posts : 1019
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/19 09:37:16 (permalink)
    +2 (2)
    dan1138
    Is there anything about the core simulator implementation that has any dependency on the version of Java run time environment, type of CPU or operating system it runs on?
     
    Intel vs AMD, 64-bit vs 32-bit, JRE 7.xx vs JRE8.xx?
     
    Have you heard of any sensitivity to anti-virus tools with the simulator?

     
    The MPLAB X installation includes its own installation of the JVM.  When you run MPLAB X, it uses the JVM that was installed with it.  It is possible to override this behavior, but you've got to really really want to do that.  (It won't happen by accident!)  So I doubt Alessandro is using the wrong JVM. 
     
    I've never heard of a simulator dependency on the JVM, anti-virus, OS, or CPU.  There's nothing too fancy going on in the simulator.  I almost kind of hope it is something like that... because it will be an interesting engineering problem!  :D
    If I had to guess...  The tools, ICD, PICkit, simulator, etc are supposed to be single-threaded.  But our clients break those single threaded rules all the time.  Maybe some other thread is coming in and changing memory or WREG right in the middle of our ADDWF execution?  Hard to imagine why this would happen.  Maybe a third party plug-in?

    Another possibility is that the issue really has nothing to do with ADDWF at all and we're investigating the wrong thing right now.
    #18
    AleMala
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2018/10/07 15:30:17
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/19 13:06:25 (permalink)
    0
    I isolate few bytes of code that doesn't work on my small pc setup.
    You should put a breakpoint at 0xD44.
    Now I can see that wreg after rotate has a wrong value in watches.
    Regards, Alessandro
    ps: hope not to be creazy !

    Attachment(s)

    Attachments are not available: Download requirements not met
    #19
    dan1138
    Super Member
    • Total Posts : 2897
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: addwf doesn't set carry ? 2018/10/19 16:24:31 (permalink)
    0
    GeorgePauley
    Another possibility is that the issue really has nothing to do with ADDWF at all and we're investigating the wrong thing right now.

    I agree that it is unlikely that this bug is in any way "normal" simulator behavior.
     
    The simulated instruction stream is a store of the WREG, an add to WREG from a source address in CODE space, and a rotate of the WREG. The simulation trace shows values that cannot result in CARRY being set yet the RRF results with the most significant bit in WREG getting set.
     
    It has all the earmarks of some kind of memory access violation.
     
    Because the OP says he is using a "small pc setup" that implies that he's running with only just enough real memory for the JRE to operate. Should this be the case good luck in finding a stable reproduction method.
     
    Feel like a snipe hunt for all of the places in the Java code where a stale pointer might get de-referenced?
     
    How long could that take? There are only a few thousand function to inspect. :)
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5