Shop OBEX P1 Docs P2 Docs Learn Events
Really simple, what am i missing? — Parallax Forums

Really simple, what am i missing?

lboucherlboucher Posts: 139
edited 2010-04-09 01:24 in General Discussion
This seems really simple to me,

unless there is something about SXB i misunderstand

Given this setup
ADC_Reading·· VAR··· Word
Tempw·········· VAR··· Word
Tempw = 362

Why does this
ADC_Reading = 375 - Tempw
not equal
ADC_Reading = 375-362

What am i missing?

Comments

  • BeanBean Posts: 8,129
    edited 2010-04-08 15:19
    Looks like a bug in the SX/B compiler.

    Use
    ADC_Reading = 375
    ADC_Reading = ADC_Reading - Tempw

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
  • lboucherlboucher Posts: 139
    edited 2010-04-08 17:29
    Hey Bean

    Thanks for the responce.
    Can you "confirm" this is a compiler bug or just speculating.

    It was late last night, so i didn't fully test eveything in a super controllered setup, but i am pretty sure this problem did happen.

    There was one other oddity to this, that i didn't mention because i think people would call me crazy.

    If i made Tempw = 360 instead of 362, it worked fine. (361 also did not work.)

    I didn't directly check the output number, i was just looking at some LED getting triggered by the rest of the code.

    Tonight i hope to get time to strip out everything except for these exact lines and directly test this.

    Also, (Not that this matters because i have the same issue when using a temp variable.)
    But the actual line of code i wanted to use was.
    ADC_Reading = 362 (Values less than 361 & values > 375 really look like they work out just fine, but again i have not directly tested.)
    ADC_Reading = 375 - ADC_Reading
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2010-04-08 17:49
    What I saw when I tried your failing example was ASM instructions generated that evaluated Tempw as a constant (ie $0f, it's address) rather than as a variable.

    something similar to

    mov ADC_Reading_LSB, #((375 - Tempw) & 255)

    That's not exactly right, but the issue is the # which means load with constant. So it would appear to be a "special case" not handled properly by SX/B.
  • lboucherlboucher Posts: 139
    edited 2010-04-08 21:20
    Mr Bean

    Your solution works, kinda a scary bug though. Seems like something that is probably lurking in many peoples code, just waiting for that extreme case to trigger the unthinkinable.

    To us not to verse in assembly, could you please describe the impact and what is going on here?

    Thanks
  • BeanBean Posts: 8,129
    edited 2010-04-09 01:24
    lboucher,
    Basically the compiler is generating the code for "wordvar = const - const" instead of "wordvar = const - otherwordvar".

    You are right, this could cause problem. I have fixed the compiler and posted version 2.00.31 in the sticky thread.
    I would advise everyone to use this latest version.

    P.S. Thanks for bringing this bug to my attention.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
Sign In or Register to comment.