Shop OBEX P1 Docs P2 Docs Learn Events
assembler code fails to run correctly on chip — Parallax Forums

assembler code fails to run correctly on chip

magnetmagnet Posts: 13
edited 2012-01-13 14:46 in Propeller 1
I have run my assemble code fine with many sets of data all with success in the simulator, yet when loaded into the propeller chip in ram or to the eeprom it fails to run correctly and never finds the correct result, thus the code never finishes. Any pointers what my next course of action should be to find where the problem is please?

Just for anyone else fearing the jump to using assembler... the speed up is amazing!

regards
magnet

Comments

  • LeonLeon Posts: 7,620
    edited 2008-01-06 21:53
    Which simulator?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-06 21:53
    magnet said...
    Any pointers what my next course of action should be to find where the problem is please?
    Post your source code.

    -Phil
  • CardboardGuruCardboardGuru Posts: 443
    edited 2008-01-06 22:11
    propeller.wikispaces.com/Common+Assembler+Bugs

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Play Defender - Propeller version of the classic game
    Prop Room Robotics - my web store for Roomba spare parts in the UK
  • magnetmagnet Posts: 13
    edited 2008-01-07 15:02
    I'm using the java pPropellerSim I saw a link to from this forum. Nice bit of software.
    The program runs 100% correctly within this simulator no matter what starting values I give it in the supplied data that I am using to test my code so code integrity would seem to be ok.
    I think the simulator is robust enough to handle a simple addition and subtraction program with no major trick programming techniques being used in it without being so buggy.

    The only thing I can think of is the indentation of the assembler code and that the simulator might be more tolerant of this, but I'm not sure this is the case with assembler, although critical in spin code.

    Consider these 2 pieces of code...

    <label> mov a,b wc

    and this one

    if_c mov a,b wc

    Does the "if_c" have to be indented even if it does not have a label in front of it?

    This is the only thing I can think of so far is the formatting of my code, despite the fact it compiles without errors and runs fine in the simulator.

    Comments welcome.
    magnet
  • LeonLeon Posts: 7,620
    edited 2008-01-07 15:17
    Post the code!

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • CardboardGuruCardboardGuru Posts: 443
    edited 2008-01-07 15:20
    Did you work through the check list I posted? I'm guessing not.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Play Defender - Propeller version of the classic game
    Prop Room Robotics - my web store for Roomba spare parts in the UK
  • AleAle Posts: 2,363
    edited 2008-01-07 16:37
    I may be the more indicated to help you wink.gif

    - The indentation does not play a role, none.
    - Instructions and conditions are parsed before labels, that means that if a "label" hapen to have the same name as an instruction, it is going to be treated as an instruction, regardless of it is indented or not.

    So;
    label mov a,b
    
    


    And
    label
    mov a,b
    
    


    And
    label
      mov a,b
    
    


    produce the same code, and the same address for the label

    Something you may want to have in account is the terminating code, at the end of your program what do you do ?, a jum to itself ?, a cogstop ?... or you just leave it open ? When coginit is executed 496 longs are copied into COG's RAM, so anything after your program will be treated as instructions.

    A sample of a non-working code may help us (me to uncover a bug maybe) to find the problem.

    Ale
  • magnetmagnet Posts: 13
    edited 2008-01-07 18:12
    DOH!!

    Broken propeller chip!

    Changed the chip and the code works! I have no idea how the chip got broke though?!?

    Regards
    magnet (highly embarrassed mode engaged) blush.gif
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2008-01-08 02:47
    need more on that 'chip broken' - doesn't cover what was going on there ... drop the code and what your 'faulty' prop did - would love to know ..

    JT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
  • magnetmagnet Posts: 13
    edited 2008-01-08 19:14
    Sorry for late reply. Got annoyed after finding the "success" was due to an old spin code in the eeprom being loaded and running ok in new chip and not my code! mad.gif
    The old chip has that smell of being fried and could be due to the plug adaptor I was using failing on me last week. When tested it shows a massive current that then fades down to a trickle. I think it did my prop chip no favours. Anyhoo, new chip in circuit and new power supply now. Old spin code examples all working so the hardware seems to be fixed. I've been using some really old code from my Amiga days to try and learn programming on this chip so forgive the complete pointlessness of the code, but the simple gist of it is to add a number to a running total and if the result is higher than the target then to subtract another number and repeat until the 2 values are equal. There are not many loops in the code and the leds flash a bit too fast so maybe should try changing the starting values to some bigger range. If the code finishes its run and the 2 results do not match then it should go into an infinite loop and keep the red led I have on pin 20 alight, which it does. The loop counting led on pin 15 does flash once per outer loop fine. If the 2 results match then it should jump to the other led routine that lights a green led on pin 18.

    Really hope someone can spot the novice mistake I have made or offer an explanation why it still doesn't work.
  • magnetmagnet Posts: 13
    edited 2008-01-10 13:12
    Has anyone spotted where the code is failing when it is run in a cog on the chip?
    Has anyone else tried running it in the pPropellerSim without any errors?

    I'm still getting these 2 results every time I've tried. Simulator fine, chip fails.

    Regards
    magnet
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-10 19:00
    Magnet,
    it was difficult for me to restrain from "optimizing" your code - but I succeded smile.gif
    I think the issue is here:
            subs  r03,temp  wc
    if_c    add   r03,v1000
    


    You seem to assume that C is set when SUBS results in a negative value. That is not the case however. It seems that the author of the simulation program erred likewise smile.gif
  • magnetmagnet Posts: 13
    edited 2008-01-10 19:38
    Page 405 of the manual states "the C flag is set (1) if the subtraction resulted in a signed underflow". Did I misinterpret this?
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-10 19:42
    Yes. A change from plus to minus is no "underflow" but a standard situation. You have to check the sign flag (by CMPS xxxx, #0 e.g.) explicitly after any subtraction.

    The meaning of C within ADDS and SUBS has been carefully chosen to allow easy multiprecision arithmetic with ADDX, SUBX

    Post Edited (deSilva) : 1/10/2008 7:47:21 PM GMT
  • magnetmagnet Posts: 13
    edited 2008-01-10 19:50
    ...and these addx and subx instructions were what you "resisted optimizing" to my code? I'm thinking they could be used for this as it has a carry that ripples along? Will try the cmps and see what happens. Thanks for your help, I was starting to think I was going mad running this simulator successfully all the time! I'm dreading when I start to try doing a useful program on this chip soon.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-10 19:55
    You should also tell the author of the simulator smile.gif
  • magnetmagnet Posts: 13
    edited 2008-01-10 20:12
    I just changed the offending lines of code to:

    subs r01,temp
    cmps r01,#0 wc
    if_c add r01,v1000


    and it still fails, so although I made a mistake, this alteration has not made the code run correctly. (Simulator still works fine! Grrr)
  • magnetmagnet Posts: 13
    edited 2008-01-10 20:24
    It *almost*works!!! deSilva... Thanks very much for your help, and I have stuck a note in my Prop manual as a reminder.

    I tried the code on some small numbers and it ran ok, but it still fails on larger numbers, so something still isn't right.

    Regards
    magnet

    Post Edited (magnet) : 1/11/2008 3:21:42 AM GMT
  • Mark_TMark_T Posts: 1,981
    edited 2012-01-13 10:42
    If you want to test for value comparisons I'd use the more readable idioms:
                cmps a, b  wz,wc
          if_b  jmp  #less_than
          if_e  jmp  #equal
          if_a  jmp  #greater_than
    
    The condition tests "if_b", "if_be", "if_e", "if_ae", "if_a", "if_ne" meaning "below", "below-or-equal", "equal", "above-or-equal", "above". The same conditions work with cmp for unsigned comparisons. It saves having to remember the meaning of Z and C after a comparison (although its not that difficult, C is set for less-than, Z for equal)

    Note that comparisons never "overflow" or "underflow" since they don't alter the operands. add and sub can overflow and underflow and in different ways for unsigned and signed values.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2012-01-13 13:02
    You are a few years late.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-01-13 13:31
    ....Only 4 ;)
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-13 13:53
    Oh .. and I really thought deSilva is back ...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-13 14:46
    It made me miss deSilva. :frown:
Sign In or Register to comment.