CMP redefined. A Parallax first!
User Name
Posts: 1,451
On the long list of potential gotchas for veteran asm programmers migrating to the Prop, surely one of the first items would be the fact that CMP doesn't affect the Z bit unless you tell it to.
I'm sure this will feel normal some day, but right now it's maddening. I want an hour of my life back!
I'm sure this will feel normal some day, but right now it's maddening. I want an hour of my life back!
Comments
-Phil
There certainly are many things to love about assembly on the Propeller. ANDN and MUXC come to mind immediately.
I knew of the existence of effects, and have used them a time or two, but somehow I was under the impression that they were more for special cases - variations from normal functionality.
Every instruction can optionally check the flags (execute the instruction or not) and every instruction can optionally set them.
Just takes a little getting used to, just like learning to drive an automatic car after a manual. Foot goes to the floor to change gear for a short time. Then, like most drivers, you'll love the auto. Same with the Prop
meanwhile, if something does not seem to be working the right way, it is easy to go to the pdf manual in PropTool (in the help menu) and just check the bit you are looking for. It will have been downloaded with PropTool.
Also, don't forget, you can always ask here. There are plenty eager to help.
The PDF is far from up-to-date, but there's plenty of more recent stuff to glean from contributors to the thread.
-Phil
Odd that. Having used a lot of different assemblers over the years I would have said that PASM has the least number of surprises. No special registers, they are all the same.No operations that work on some registers and not others etc etc.
It is extremely regular and self consistent. One hardly has to read the huge FM to get things working once you are aware of the operations available and the simple ideas about conditional execution and writing out the flag bits.
I do sympathise that if one has missed those simple core ideas then a world of surprises awaits:)
"Trap: The Propeller has a TEST instruction that lets you set flags based on
the outcome of ANDing the instruction’s source and destination arguments.
But be sure to tell it which flags to set using WZ and/or WC. This doesn’t
happen automatically, just because it’s a test instruction."
I'm loving Tricks 'n' Traps already. Thanks!
I realize that in other assemblers the Z and C flags are written by almost every instruction, and quite often there is no way to disable that. However, this feature of the prop makes LMM PASM possible. The instructions in the LMM PASM interpreter loop don't affect the the Z and C flags, which allows it to fetch an instruction from HUB memory and execute it as if the LMM PASM code resided in cog memory.
FWIW, 60 seconds ago I read this tidbit in Tricks 'n' Traps:
"Trap: In working with the Propeller, the biggest trap of all is the set of
preconceived notions brought to bear from work with other microcontrollers."
Amen, bruddah.
-Phil
In the search for answers, I just came across this file from Drone. How is it that the ASM cog doesn't look at the first four bytes of the sine table as its first instruction? Is the PropTool smart enough to detect a table and relocate it below the code? What page (of the 399-page manual) is this on? It seems remarkably odd.
When I started with the prop I decided that to learn the assembler I'd write a simulator... many months later, some omissions in the manual, unclear details and preconceptions made this a very interesting trip full of discoveries (read my sig). And I haven't been so wild like others at programming. If I keept it simple I'd understand it later, perhaps
However you are absolutely correct to notice this as a potential code problem. ... you can however test your finding by placing a ... jmp #$ just before the sine table. Alternatively you can place a ... long $577C0000 for the same result. This basically creates an endless loop or a jump to itself.
Edit: long $577C0000 should be long $5C7C0000
I'm pleased to hear that execution begins where you tell it to begin. It seems consistent with the general philosophy of the Propeller - complete flexibility.
I may not want the processor to begin execution in a table of preassembled instructions, but someone like kuroneko might. It might allow an inquisitive person to experiment with instructions that the assembler couldn't be made to assemble.
Also, I apologize for an OT question. Possibly I should have started a new thread. But thanks for answering it anyway, Mike! It gives me much to think about.
Thanks Beau. What a great idea!
There can be a benefit for this .... as long as the CON bits (18..21) in the long are Zero, a NOP instruction is evaluated. This means that you can use all of the other bits for storing data... MOVs, MOVd, MOVi makes this convenient. So if you wanted to be tricky with your code, you could store valid data under the disguise of a NOP instruction.
"Now I'm officially puzzled. Execution passed right through" - location in the program is critical and can change as the program changes ... use F8 to see what it is first with a ... jmp #$ instruction, then replace it with the equivalent long instruction (remember the byte order is reversed)
Dave,
your right, it should have been $5c7c where I transposed it as $577c ... still it is $5c7c0000 if you are jumping to the org 0 entry point but if you are jumping to the 4th long in your PASM program it would be $5c7c0003
@User Name, Dave points out that BST creates a listing file. I highly recommend using that. The listing is probably one of the most powerful tools available for understanding code once you know PASM ... other than a good debugger
For my own PASM coding, I use the Propeller DataSheet PASM instruction listing since it is a good summary in all in one place. If I have to dig further down, I'll use the Propeller Manual. Starting with the Propeller Manual is very frustrating though.
Example program to Toggle P0
PASD may help you discovering the wonderful world of PASM:
http://forums.parallax.com/showthread.php?121946
Andy
This will only work if the data is only using the lower 8 bits (a byte) of each long.
The prop will think it's just NOP as the it's i-field is all zeros.
By making the table the power of 2 long (128 longs etc), you can increment the counter fast
and it will always stay between 0 and 127 by doing this below.
ADD Counter, #1
AND Counter, #%1111111 ' make sure it never rolls past 127
Can also use ANDN Counter, #%1<<8 ' remove bit 8 (turn 128 in to 0)
The body of knowledge contained within this forum is simply amazing.