Shop OBEX P1 Docs P2 Docs Learn Events
ptra[index] vs ptra++[index] — Parallax Forums

ptra[index] vs ptra++[index]

using PNUT V35L i compile this little listing:

DAT
    rdbyte $1, ptra     '1      $FAC40300 
    rdbyte $1, ptra[0]  '2      $FAC40300  
    rdbyte $1, ++ptra   '3      $FAC40341 
    rdbyte $1, ++ptra[1]    '4      $FAC40341 

Line 1 and 2 produces the same opcode. So index=0 means you can omit it.
line 3 and 4 produce the same opcode. So index=1 means you can omit it.

somehow i do not understand why the index is based 0 on line 1 and 2 but seems to be based 1 on line 3 and 4?

can someone enlighten me?

Comments

  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2021-04-21 18:14

    With PTRA++/++PTRA, the index is what gets added to PTRA, so it defaults to 1.

  • SuracSurac Posts: 176
    edited 2021-04-21 18:42

    ah so the syntax is misleading. in line 3 and 4 is no index but a operand for an addition.

    rdbyte $1, ptra++[3] means "use ptra then add 3"

    and

    rdbyte $1, ++ptra[3] means "use ptra+3 then add 3"

    but

    rdbyte $1,ptra[3] menas "add 3 to ptra and use it, but do not change ptra"

    right?

  • The syntax may seem misleading, but it makes sense.

    rdbyte $1, ptra means "use ptra"
    rdbyte $1, ptra++ means "use ptra and then add 1"
    rdbyte $1, ++ptra means "add 1 and then use ptra"
    rdbyte $1, ptra[3] means "use ptra + 3"
    rdbyte $1,++ptra[3] means "add 3 and then use ptra"
    rdbyte $1, ptra++[3] means "use ptra and then add 3"

    It seems logical to me.

  • hmm

    doesn't it mean

    rdbyte $1,++ptra[3] means "add 3 and then use ptra"
    rdbyte $1, ptra++[3] means "use ptra and then add 3"

    add 1 to ptra either before or after the operation and use a offset of 3 to the value used?

  • SuracSurac Posts: 176
    edited 2021-04-22 09:11

    @msrobots said:
    hmm

    doesn't it mean

    rdbyte $1,++ptra[3] means "add 3 and then use ptra"
    rdbyte $1, ptra++[3] means "use ptra and then add 3"

    add 1 to ptra either before or after the operation and use a offset of 3 to the value used?

    That's what it means in C. But unfortunately, Chip simply ignored C and @"Dave Hein" is right.
    I also was lured into the "C" interpretation of the syntax and collided with a "syntax iceberg". Now my brain is sinking and all passengers rush to the lifeboats :smile:

  • SuracSurac Posts: 176
    edited 2021-04-22 09:23

    Also to mention PNUT accepts some real wired syntax errors and just emits something

    • rdbyte $1F , ptra++[##-$10] (impossible instruction) gets to RDBYTE $1F, PTRA-- [##$10]
    • rdbyte $1F , ptra++[##$8_0001] (field size of index ignored and misused sign bit) get RDBYTE $1F, PTRA-- [##$7FFFF]
    • rdbyte $1F , ptra--[##$-8_0001] (sign in index should not be possible) gets RDBYTE $1F, PTRA++ [##$13881]
    • rdbyte $1F , ptra--[#$8] (gives a syntax error, because non ## constants must be written without # inside index)

    I know most of the above instructions are brain dead all the way, but i use PNUT to compile such things to test if my disassembler is able to decode the instruction

Sign In or Register to comment.