ptra[index] vs ptra++[index]
Surac
Posts: 176
in Propeller 2
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
With PTRA++/++PTRA, the index is what gets added to PTRA, so it defaults to 1.
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?
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
Also to mention PNUT accepts some real wired syntax errors and just emits something
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