Newbie assembly questions
william chan
Posts: 1,326
Consider the simple ASM code below
Questions.
1. Does "par" stand for "Propeller Accumulator"?
2. Does the return value always have to be the 1st parameter?
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
said...
PUB AddNums(Num1,Num2)
Num1_ := Num1
Num2_ := Num2
cognew(@entry, @Num1)
DAT
org
entry add Num1_,Num2_ 'Add Num1 to Num2
wrlong Num1_, par 'Return result to Num1
CogId CogNum 'Get COG ID
CogStop CogNum 'Stop this COG
CogNum long 0 'Reserved variables
Num1_ long 0
Num2_ long 0
Questions.
1. Does "par" stand for "Propeller Accumulator"?
2. Does the return value always have to be the 1st parameter?
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I am 1011, so be surprised!
Advertisement sponsored by dfletch:
Come and join us on the Propeller IRC channel for fast and easy help!
Channel: #propeller
Server: irc.freenode.net or freenode.net
If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
There's no "return value" from an assembly routine since the assembly routine doesn't really return. It just keeps running or the cog stops.
This value (a 14 bit number positioned to work as the address of a long or a table of longs) passed to the cog is used to pass information into and out of the cog.
Does it always have to be the first parameter?
But curiously after
there is no
return Num1_
I wonder why....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
@entry refers to the address in HUB memory where an assembly language program, to be loaded in the COG exists. When the cognew is executed, the COG loads it's memory with the code located at @entry. @Num1 "points to" the address in the HUB that is the container for the value of Num1. This address, with the lower two bits set to 0, gets loaded into the PAR register as a single passed value to the assembly language program running in the COG. The assembly language program then can read this value and use it to fetch additional information from the HUB in a programmatic way. Say, values are stored sequentially in the HUB. Passing the first one is all that is really needed in the COG for the program to then fetch additional ones, as offsets from the first one given in PAR. ...or, perhaps nothing is passed to the COG as it knows where it needs to look in the HUB. In that case, the PAR register really does not matter and most of the time people just then pass a zero.
PAR is read only to the assembly language program running on the COG.
in the add:
There is no accumulator, in the traditional sense of this word used to describe a working register!
When you add two numbers on a register based CPU, you do something like:
1 load accumulator with operand
2 add accumulator to another operand in memory
3 store accumulator to memory.
There would be two operands somewhere in memory as well, ignoring immediate (operand part of instruction) type of addressing.
On the Propeller, an add happens between two addresses, meaning all of that just ends up being:
1 add destination operand, source operand.
Still, there are two operands in memory, but only one add instruction. When the add is complete, the destination will contain the sum, eliminating the need to explicitly load and store.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
Really, this instructs the COG to write the value contained in Num1_, to the HUB address contained in PAR.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
wrlong goes backwards compared to mov.
I wonder why Chip decided to design it backwards....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
How to do
in Parallax assembly?
Sorry for so many questions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."
- Bjarne Stroustrup
I'm not going to give you the code for division, you can get that from Propeller Guts: http://forums.parallax.com/showthread.php?p=572669
So assuming the variable·delay has the contents of clkfreq/200:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
In spin, if I do a waitcnt(clkfreq * 5 + cnt)
if the cnt register is just about to wrap, will I get unexpected results?
Same in PASM?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Concentrate on understanding the problem, not applying the tool
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Good beginner point, though, that waitcnt can't wait beyond 2^32 clocks. I've done a;
To wait for significant periods of time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Concentrate on understanding the problem, not applying the tool