PASM help with "arrays"
Hi,
Can someone help me with PASM?
I have 3 res variables. A, B and C.
C is res 64.
B is in index
A need to point the the right place in C.
All my values should be bytes.
So I do:
Now, I'm missing one more instruction to have A pointing to the address stored in A. I tried to play with @ an # with no success and read also fiew PDFs, but I'm not not able.
So what should I put to have A pointing to the right place?
On a post from Mike (http://forums.parallax.com/showthread.php?p=601870) I found:
So should I "simply" do that?
Thanks,
JM
Can someone help me with PASM?
I have 3 res variables. A, B and C.
C is res 64.
B is in index
A need to point the the right place in C.
All my values should be bytes.
So I do:
mov A, #C add A, B
Now, I'm missing one more instruction to have A pointing to the address stored in A. I tried to play with @ an # with no success and read also fiew PDFs, but I'm not not able.
So what should I put to have A pointing to the right place?
On a post from Mike (http://forums.parallax.com/showthread.php?p=601870) I found:
'' Here's a simple example of table lookup in assembly. '' This particular example takes a table index in "ptr" '' and sets the "data" to the word value from the table. '' There's no range checking. If you want long values, '' just eliminate the shifts and masks (*). You can use '' the same kind of logic for byte values. DAT org 0 test mov ptr,#2 ' for an example, get third value call #look ' note table indices are 0 to n-1 :stop jmp #:stop ' no checking for out of range look mov data,ptr ' ptr is a table index (0 to n-1) shr data,#1 ' divide input value by 2 to get (*) add data,#table ' long word index, add table address movs :inline,data ' have to use instruction modification nop ' need pause here for pipelining :inline mov data,0-0 ' get long value from table test ptr,#1 wz ' do we want odd or even half (*) if_z and data,mask ' if even, take lower 16 bits (*) if_nz shr data,#16 ' if odd, take upper 16 bits (*) look_ret ret table word $0000 word $C0C1 word $C181 word $0140 word $C301 word $03C0 word $0280 mask long $FFFF data res
So should I "simply" do that?
mov A, #C add A, B movs :inline,A nop :inline mov A,0-0
Thanks,
JM
Comments
Either change it to long and take care that the pointer accesses the right position or read two words at the time and use a mask/shift accordingly, I'd use longs unless memory is a constraint.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim
@JM,
It will be easier and faster to hold your table in HUB RAM and access it using rdbyte and wrbyte.
You will have to pass a reference to your array from Spin to PASM at cog startup using cognew(@pasm, @parms).
While rdbyte can take up to 22 clocks to get started, you can reduce that time to 8 clocks by keeping the access in "the window."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.
Post Edited (jazzed) : 4/12/2010 9:08:04 PM GMT
@jazzed, what is he hub faster that the cog memory? I will have all the cogs running the same code, so all accessing the hub. Will it not be faster to access the COG memory instead? I'm trying to do a kind of stack. I'm working on that 8h a day for the 3 last days and starting to find PASM difficult [noparse];)[/noparse]
I don't want to post my code yet because you will clean it in 10 seconds and propose a better solution and I don't want to be frustrated [noparse];)[/noparse]
To put on the stack, I need this code:
Duration: 5x4 cloks = 20 clocks.
Your solution (Not sure, correct if I'm wrong):
Duration=4+4+7..22 so min=15 max=30.
Is it really better?
Also, what can I use to trace the PASM? I tried pPropelleSim, but it's petty buggy. GEAR does not display instruction and memory and is only working on windows. Pretty difficult to find a good tool. Is Parallax tool coming with a debuger like for the Javelin?
JM
Your two examples illustrate it fairly well:
Duration: 5x4 clocks = 20 clocks.
Duration: 2x4 + 1*8 clocks = 16 clocks minimum
Duration: 2x4 + 22 max clocks = 30 clocks maximum.
Clearly, if you can't keep hub accesses in the window, the intracog solution is faster.
Problem is you need 4x the memory in the COG and if the data is only byte wide, that's a big waste.
To do the same byte size operations intra-cog requires more instructions.
I use a tool I developed for on-chip debugging, but it's not for everyone [noparse]:)[/noparse]
There is a GUI add-on for that, but it is not ready for prime-time as they say.
Perhaps you should try GEAR since you don't have a Propeller yet.
I bet Ale would help you with whatever issues you have with ppropellersim though.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
May the road rise to meet you; may the sun shine on your back.
May you create something useful, even if it's just a hack.