using coginit in assembler
Chris Micro
Posts: 160
Hello,
how can I use coginit with symbolic labels? Here is my code example: cog 0 starts with the coginit instruction cog3.
But my problem is, that I have to write the startadr as an absolut value. How can I tell the compiler to to it automatically.
how can I use coginit with symbolic labels? Here is my code example: cog 0 starts with the coginit instruction cog3.
But my problem is, that I have to write the startadr as an absolut value. How can I tell the compiler to to it automatically.
org 0 start0 shl startadr,#4 add startadr,#3 'cog3 coginit startadr end0 jmp #end0 startadr long $38 fit 496 '####################### COG3 ######################################################### org 0 start mov r0,#$00 'clear screen command wrbyte r0,#PUTCHAR
Comments
or from within the DAT section with
on my emulator I have no Spin interpreter. Therefore I will use the version with the DAT-section. Is the DAT section always starting from $10 ? What happens if I have multiple objects with DAT sections, does it work?
Thanx,
chris
I don't know if this is any use but bstc has an @@@ operator that will get the correct address for you.
So:
Then bstc can also output the raw binary of the PASM with the -c option
bstc -c filename
According to Brad:
It drops a raw .bin file of the first objects DAT section with no header, method table or spin code.
Which might help if you only want one DAT section out I guess.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
It's not a bug, that is by design. You are only referencing the address of the label within the object. It happens to work the way you describe for the top object as the compiler always starts the object at $10, however any sub-objects will start wherever the compiler puts them.
There was an "extension" implemented my mpark in Homespun that allowed you to use @@@ on a DAT label, and that would return the hub address of that particular label, but while many requested it, I don't think it's ever been used in anger.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Missed it by ->" "<- that much!
Edit: Just verified, $10 is only valid for the top object.
Post Edited (kuroneko) : 7/2/2009 10:24:27 AM GMT
Just now I don't know what I'm looking at with the following code and listing from BST.
Where no @ is used the listing shows a value of 4 for startaddr0.
Using a single @ results in $3C for staraddr1, as expected $10 away from the start HUB address.
Using @@ results in startaddr2 being zero.
Using @@@ gives what we want, the actual HUB address of start.
So what is happening in the @@ case?
From the listing:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
That's a bug in the compiler. It's fixed in the latest version (which with any luck will be released tomorrow - I'm running all my validation checks at the moment). Ale picked it up a while back. @@ is not valid in anything other than a SPIN block.
The other thing I'd forgotten about is @@@ is actually valid spin. Not at all useful, but valid. The Parallax compiler parses and generates code from it. It treats it as @@ @ together.
Has anyone actually used the @@@ operator in anything useful?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Missed it by ->" "<- that much!
Post Edited (BradC) : 7/2/2009 10:33:22 AM GMT
Now I'm confused: You mean the spin tool and your bstc gives the same result for @@@?
So, no, not the same as @@@ in BSTC.
BradC: Actually I was contemplating replacing some Spin code that sets up some pointers in ZiCog/MoCog with @@@ the other day.
I decided against it thinking that maybe someone somewhere might want to remove the #defines etc we now have and compile in the Prop Tool again.
Then again @@@ might still be useful if it is desired to compile a Spin free version of the PASM modules.
Then again I could put more ifdefs around use of @@@.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
That is the reason, why I asked if it is compatible. I made the test.spin file for the emulator with BSTC but in my opinion it is useful if people can use the standard Prop Tool.
The emulator can be started in the linux console with
./propsim.out
it then loads the file "test.binary" and executes the code. No installation is needed.
I created test.binary with BSTC and it is useful to have the @@@ operator. I don't like the version with the +$10 bytes because it is limited to the top object.
Quite right to. One should avoid "magic numbers" as much as possible when programming. There is a solution to this, instead of using +$10
1. Declare a variable in DAT that will hold the objects base address
object_base long 0-0 'HUB address of this object
2. Initialize it in Spin with this magic phrase:
object_base := @@0 'Set up the base address of this object
3. Declare your pointer(s) in DAT section (Which point to HUB data) with the @
dispatch_tab_addr long @dispatch_table
3. Add object_base to those pointers:
add dispatch_tab_addr, object_base 'Fixup this object offset to HUB real address
Could do that last step in Spin before starting the PASM I guess.
I have used this in old versions of the 8080 emulator. Not sure I can fathom why it works or remember who suggested it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit the home of pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
You're already doing half the fixup in Spin; why not just do the whole thing in one step:
up getting the parameter value of the second one, because launching a cog is asynchronous to the execution
of the spin interpreter.
dispatch_tab_addr := @dispatch_table
my Emulator has no Spin interpreter yet. I would need a spin.binary.
And I don't know to which address I should set PAR for the first calling of the interpreter.
Not sure now why the old PropAltair does it the long way except that PropAltair used a lot of little LMM routines and I fixed up their start addresses in one place dynamically in PASM rather than with a whole list of Spin assignments.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.