The use of "#"
cts566
Posts: 4
Is there any good guide for knowing when to use # or not in Propeller Assembly?
I have read manuals and guides, but there doesn't seem to be any hard and fast rules to the "#".
Thanks,
AP
I have read manuals and guides, but there doesn't seem to be any hard and fast rules to the "#".
Thanks,
AP
Comments
"JMP #5" = the value 5 is encoded directly into the instruction "source" bit-field, and is copied to the COG program counter, when the instruction is executed. This is a direct jump, where the value inside the instruction is to be loaded directly into the program counter.
"JMP 5" = the value 5 is encoded directly into the instruction "source" bit-field, and is the address of a COG memory location that contains the value to be loaded directly into the COG program counter. This is an indirect jump.
Edit: Since we were talking about personification on an earlier thread, maybe this is a good time to use it. If I tell you to go through the third door to the right, that's a direct reference, and that's when you use the octothorpe. If I were to tell you go through the door that Phil tells you to go through, that's an indirect reference, and it's not when you use the octothorpe.
Only the 9 bit "source" bit-field of an instruction is used in tandem with the "#", or otherwise known as the octothorpe.
The thing to remember is that when the octothorpe is present, the value contained in the instruction "source" bit-field will be used directly as an address, or value. For jumps, you always want it, unless you have a good reason why not, because indirect jumps are not used much in PASM.
Other instructions might vary.
Let's take the shift instruction as one other easy example.
There are basically two cases:
1. The number of bits to shift is known, and can be directly specified in the instruction; you use the octothorpe for this case: "SHL address, #7"
2. The number of bits is not known, and will be calculated as the program runs; you may or may not use the octothorpe
In the not known case you can either:
2a. use a COG memory location to hold that value for use by the shift instruction when it executes; do not use the octothorpe: "SHL address, 7"
,or
2b. you can directly modify the PASM instruction before the shift instruction executes, so that when it is actually executed the intended number of shifts then occurs. For this, you do use the octothorpe because you want the value to be directly used, not serve as an indirect address after it has been modified by some other instruction.*
*PASM includes self-modify instructions, movd, movs, movi for this purpose.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
8x8 color 80 Column NTSC Text Object
Safety Tip: Life is as good as YOU think it is!
Post Edited (potatohead) : 3/3/2010 3:42:42 AM GMT
and not the address that the number is stored at.
With jpm, you use # as to point to a location that you have put a name on.
The Assembler will convert this to machinecode and will put the correct value there.
But I think I can add a few additional points that have not yet been made (someone please correct me if I got these wrong)
First, when variables are being declared, the # is not used preceding digits.
Second, when using variables, the # is not used before the name. But names from a CON section look like variables but are treated like immediate numbers, both in the code section and in the data section, so on casual reading, there seems to be a random mix of "#names" and "names".
CON
con_name = 4
...
DAT org
mov myvalue, #con_name
mov myvalue, dat_name_x
mov myvalue, #4
' data
dat_name_x long con_name
dat_name_y long 4
myvalue res 1
Better just to learn what # really means.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't click on this.....
- "instruction destination, source" PASM says "Propeller, interpret the source as the content which lives at the source address."
- "instruction destination, #source" PASM says "Propeller, interpret the source as a number or an address and not the content of an address."
- "jmp #source" says "Propeller resume execution at the source label address."
- "jmp source" says "Propeller resume execution at the data contained at the source label address."
Post Edited (jazzed) : 3/3/2010 2:19:50 AM GMTAll these have often come up as confusing, I think.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I should be typing in Spin now.
Coming soon. My open Propeller Project Pages and favorite links index.
Post Edited (VIRAND) : 3/3/2010 6:23:20 AM GMT
Nobody says octothorpe apart from 1960's telephone engineers (according to wikipedia) [noparse];)[/noparse] Better to just use # then it can be translated as appropriate, I will read hash, others pound and you and your fellow telephone engineers octothorp/octothorpe/octathorp/octatherp [noparse];)[/noparse] [noparse];)[/noparse]
All,
Firstly on page 241 of recent manuals there is a bit about the # symbol.
Much of the confusion about # comes from not understanding how the assembly instructions are made up of 32bits containing the instruction name and 9-bit fields for source and destination. For each command in the docs you will see something like this:
SValue (s-field) is a register or a 9-bit literal ....
So you supply an address of a register (which is the same as its name) or you supply a number you want to be taken literally and immediately(just use it don't use it to get some other number). So to add 10 to a register you do add total,#10 because you want 10 to be added to the total rather than the value stored at memory address 10.
This is also why you can't do add total,#600 because 600 won't fit in 9 bits.
For the jump commands remember that the label is the address of that part of code so you want the code to go to that address directly, hence the #.
Graham
There is also the issue of what exactly the manual is for, it is more than a datasheet but less than a learn programming book.
Graham
Your point is nicely taken. I'll go OT here for a moment, because words are fun, and "playing" with them some, not being inhibited in expression, has some value.
It's funny you mention telephony engineers because I worked with some of them last week, and paid one of them a considerable amount to assist in the "programming" of a phone PBX. We here, from the perspective we have, would call that "configuration", and the differences start there, and build rapidly! I've experienced clashes of this kind on occasion, and always react the same way; namely, to put some of what was learned to use just enough to solidify it, and make it a part of my working lexicon. So, I'll use it some to explore the elements that contribute to it, and then move on.
Had I done a bit more of that last time, I wouldn't have been paying for stuff this time. The concepts behind the PBX are simple, easily understood, and not difficult to manipulate, but the terminology gets in the way enough to be a problem. Of course, this is by design, and I don't consider it nefarious, just costly, and something to be avoided where it makes sense.
What my life experience tells me is that when I feel that sense of intrigue that comes with learning a new thing, that's a clear sign that element of expression is not yet solidified enough to be permanent. Why learn it, only to have it forgotten, confusing, and or useless, requiring dollars and or time, which are one and the same a subsequent time around?
One of the tasks we have in front of us, where I work, is dealing with people over the phone. Introducing some of them to octothorpe, in a playful way, has saved a considerable number of words, and that translates into time, which presents as opportunity. Until recently, it was "that pound sign", or "shift 3 on your keyboard", etc... All of the other characters are largely understood by their actual name, meaning I can say, "tilde, asterisk, ampersand, etc... with this one being no different, over some time.
There is a self interest there that also drives why I will sometimes do this kind of thing.
Finally, there is a subtle element in play that I take seriously on a lot of levels. Branding, community, messaging, etc... all will depend on specific word use. If a person takes the time to recognize labels, coined phrases, uncommon word use, and other contributing elements, one then can easily recognize when and why said messaging occurs, and decide whether or not to buy into it, or more importantly: propagate it, build new messaging, or leverage what it out there.
In the case of "our users", of "the software", some company, branding specific, precise language, stands out nicely, and over the years has served as one of our subtle, but recognizable and potent differentiators.
So there you go. It's a bit more complex than what I read essentially as, "don't pick up bad habits from telephony guys" [noparse]:)[/noparse]
We can now return to direct, vs, indirect addressing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
8x8 color 80 Column NTSC Text Object
Safety Tip: Life is as good as YOU think it is!
Post Edited (potatohead) : 3/3/2010 5:08:09 PM GMT
(from that page)
When we discussed this, and the word "octothorpe" first appeared here, there was some nice discussion about "immediate", vs, "direct", and I actually was one of the ones who had latched onto "immediate" as the primary term for this kind of addressing. The better case for direct was made, and I updated that in my own lexicon, moving "immediate" to the status of a qualifier, or descriptor, instead of the core word element needed to differentiate this addressing from indirect addressing in general. There isn't a material difference between doing that, and my remarks above on "octothorpe". Words are words. We learn them, and use them as the tools they are.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
8x8 color 80 Column NTSC Text Object
Safety Tip: Life is as good as YOU think it is!
Post Edited (potatohead) : 3/3/2010 5:21:07 PM GMT
Graham
# = weight pound
£ = money pound
'In most regions of the United States, the symbol is traditionally called the pound sign, but in others, the number sign. This derives from a series of abbreviations for pound, the unit of weight. At first "lb." was used; however, printers later designed a font containing a special symbol of an "lb" with a line through the verticals so that the lowercase letter "l" would not be mistaken for the numeral/digit "1". Unicode character U+2114 (℔[noparse];)[/noparse] is called the "L B Bar Symbol", and it is a cursive development of this symbol. Ultimately, the symbol was reduced for clarity as an overlay of two horizontal strokes "=" across two forward-slash-like strokes "//".'
Where is your "#" character, and isn't it kind of funny how the discussion goes. Almost like "the artist formerly known as..." kind of thing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
8x8 color 80 Column NTSC Text Object
Safety Tip: Life is as good as YOU think it is!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
It can lead to confusingly convoluted code [noparse];)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
Potatohead, the # is next to the return key beneath ] and on the same key as ~. Use this knowledge wisely!
Graham