Shop OBEX P1 Docs P2 Docs Learn Events
calculation error — Parallax Forums

calculation error

Spiral_72Spiral_72 Posts: 791
edited 2011-01-01 22:23 in BASIC Stamp
I read about orders of operation in the manual..... at least I THOUGHT I did. Why doesn't the following give me a correct address???

ptr is a Word sized pointer variable. Movem is a DATA table containing numerous pairs of BYTE sized numbers


ptr=Movem
READ ptr+x*3, y



Following the orders of operation, it should:

add the variable ptr to the product of the variable x and the constant 3

This was supposed to give me the address to lookup (via READ) data in my table. Instead it give me garbage. Gosh, it took an hour to figure out what was going on :(

If this is the way it is, and I'm not doing something stupid, BE AWARE to use yo' parentheses!!!!!

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2011-01-01 22:01
    Smile, can I delete this post???

    At the risk of sounding completely retarded I finally found it on page 103 under "Orders of Operations". Go figure.

    Calculations are performed left to right. There are no orders or operations, or rather that IS the order. Of course parentheses work.


    Oh, well. Maybe someone will learn from my stupidity.
  • FranklinFranklin Posts: 4,747
    edited 2011-01-01 22:23
    It's not stupidity if you learned something. I've seen stupidity described as someone doing exactly the same thing over and over expecting different results.
Sign In or Register to comment.