Re MOVS instruction as used in Keyboard.spin file what does it mean..
OzStamp
Posts: 377
Hi.
Trying to understand what the code does in· the keyboard.spin object.
Scanning thru the code..
There are 3 spots where the instruction MOVS· napshr,#X· (X is ·3 values 18 or 16 or 13) is
loaded .. I understand that I think..
At also the same locations there is the Call to the NAP routine..
The NAP routine has the napshr... shr instruction in it· ..see below..
nap··················· rdlong· t,#0·················· 'get clkfreq
napshr··············· shr···· t,#18/16/13········· 'shr scales time
···················· ··· min···· t,#3··················· 'ensure waitcnt won't snag
··················· ···· add···· t,cnt·················· 'add cnt to time
··················· ···· waitcnt t,#0·················· 'wait until time elapses (nap)
nap_ret
Nowhere is the napshr register defined not in the Res or long area ?
What am I missing here..?
Is this one of those automatic allocations of variables.. as it is in the·NAP routine..?
cheers·· Ron Mel oz
·
Trying to understand what the code does in· the keyboard.spin object.
Scanning thru the code..
There are 3 spots where the instruction MOVS· napshr,#X· (X is ·3 values 18 or 16 or 13) is
loaded .. I understand that I think..
At also the same locations there is the Call to the NAP routine..
The NAP routine has the napshr... shr instruction in it· ..see below..
nap··················· rdlong· t,#0·················· 'get clkfreq
napshr··············· shr···· t,#18/16/13········· 'shr scales time
···················· ··· min···· t,#3··················· 'ensure waitcnt won't snag
··················· ···· add···· t,cnt·················· 'add cnt to time
··················· ···· waitcnt t,#0·················· 'wait until time elapses (nap)
nap_ret
Nowhere is the napshr register defined not in the Res or long area ?
What am I missing here..?
Is this one of those automatic allocations of variables.. as it is in the·NAP routine..?
cheers·· Ron Mel oz
·
Comments
What is nice is that it only modifies the source bits. Have a look at the MOVI and MOVD instructions as well. They do the same thing only with the instruction and destination parts of the instruction.
Just guessing that this is part of a timing or delay routine?
And very OT but not worth a thread, do you sell the Hydra book in Australia?
Note that the operand part #18/16/13 is just a comment, which shall indicate this wil be filled by one of those values later. However I should consider that as a bad practice -- too tricky!
There are some remarks wrt self modifying code in my Tutorial...
This is an alternative version of NAP in a cleaner style.
Post Edited (deSilva) : 2/23/2008 11:26:39 PM GMT
--Chuck
Thanx for the pointers.
I do understand the MOVD MOVI and MOVS instructions.
What is a little cryptic and still is..read on if you wish..
Walking thru that Keyboard.spin object just for the purpose of me learning
as to how it does what is does...I could not see anywhere down the bottom
where it defines all the LONGS WORDS and RES's .. I could not find the
NAPSHR variable(REGister)...that is a little odd to me.
So what from I gather from DeSilva comment is that the NAPSHR in the
NAP routine· NAP....NAP_RET· it is defined there..see below ther..
nap···················· rdlong· t,#0·················· 'get clkfreq
napshr················ shr···· t,#18/16/13········· 'shr scales time
······················ ·· min···· t,#3··················· 'ensure waitcnt won't snag
···················· ··· add···· t,cnt················· · 'add cnt to time
····················· ·· waitcnt t,#0··················· 'wait until time elapses (nap)
nap_ret················ ret
To me that shr· t,#18/16/13 also looks like a divide to me .. very cryptic..
Nowhere in any doc's could I find anything related to that exact syntax.
I have read DeSilva's asm tutorial numerous times and refer back to it often..
It is usefull very usefull..
Also PhiPi tricks and traps is printed out for ready persual at all times...
The NAP routine to me is a simple PAUSE routine and the way it is written
seems to me over complicated..I am sure there is a reason for it the way it is
done but that eludes me presently..
Laerning and loving it..
cheers Ron Mel OZ..
The NAP routine is a simple PAUSE routine, but it allows for different pause times by modifying the shift count before calling the routine.
Yes, the notation "18/16/13" is confusing to the uninitiated. It looks like a divide because that's what the assembler does with it, but it's really a cryptic comment to show the possible values in the immediate source operand. The MIN instruction just ensures that the WAITCNT doesn't hang up because the wait time is too small. Remember that this routine is supposed to pause for a known time regardless of the clock speed being used (within reason).
your comments are as strange to me as - obviously - my comments to you!.
You SEE that label NAPSHR don't you? That's it, nothing else.
I also commented on #18/16/13 and said that is a bad practice as it will confuse the naive.. so it has despite my warning
It is a COMMENT! It will say: Put 18, 16 or 13 here! Tricky! Too tricky
This line should best read:
as most people are now accustomed to the 0-0 which is also a comment however ....
And: No, a pause routine can't be shorter. Have a look a my alternative: It's even longer (though much clearer)
Post Edited (deSilva) : 2/23/2008 11:09:06 PM GMT
Yes it is confusing, but I think you have it, I've highlighted two bits from the code above:
See the napshr ? That is the label that represents where the SHR instruction is. And the argument #18/16/13 is bogus because it is going to be overwritten by the MOVS instruction. So the programmer has taken the opportunity to add some documentation as to the values that might be placed there, in this case 18, 16 or 13.
--Chuck
Just can see that T parameter.. that must be the parameter that holds the Clock speed..
Good pointer thnx.
DeSilva read my last post properly... I did thank you and mentioned
===================
So what from I gather from DeSilva comment is that the NAPSHR in the
NAP routine NAP....NAP_RET it is defined there..see below ther..
===================
cheers ron
--Chuck
labels .. labels..
Can you see though how napshr is not defined anywhere as a REGISTER)
That is the exact issue that confused me .. understood now..
Yep lots of help.. thanks again guy's
ron
Post Edited (OzStamp) : 2/23/2008 11:52:27 PM GMT
It's just as in all old computers, starting with the Manchester Mark I
Post Edited (deSilva) : 2/23/2008 11:37:13 PM GMT
I really did mean just REGISTER .. edited my post..
thnx soory about the confusion..
cheers ron
Hi Ron, I had the same misunderstanding when I started programming in Assembler. If someone is collecting tidbits for an updated FAQ then we should put something like this in it:
REGISTERS vs CODE vs MEMORY
Each COG has exactly five hundred and twelve 32 bit words of memory that it can address numbered 0 through 511. By design, the source and destination fields of every assembler instruction are 9 bits which means they can hold the address of any one of these locations in memory. By convention, if a memory location is being used to hold data it is referred to as a "register" however unlike other computers you may have been exposed to there is no specific qualities for the first 496 locations that make them more like registers or more like memory. The last 16 locations however have specific roles and they are discussed in the propeller manual, COG programs and their data are thus restricted to the "lower 496" in practice. Also unlike many architectures the propeller does not have a notion of an "accumulator" or a set of bits which are not present in any memory space. All of the transforming operations available in the instruction set such as ADD, SUB, XOR, AND are just as adept at transforming a memory word that is holding an instruction as they are transforming one that is simply holding data. There are even specific instructions, MOVS, MOVI, and MOVD which are designed to operate on specific parts of a memory location which are associated with the Source, Instruction, and Destination areas of a propeller assembly language instruction. These special move instructions facilitate the development of self modifying code which can make possible some more complicated transfer operations such as move indirect or move with offset.
Post Edited (Chuck McManis) : 2/24/2008 1:26:13 AM GMT
What you wrote is good except that some of the registers do have special qualities (the last 16 in memory). Some of them are read-only like INA / INB / CNT / PAR. If these are used as a destination, the actual memory location is used rather than the special register function.
@deSilva I know you covered it in your tutorial, I observed however that both I and Oz have read your tutorial and we both missed the significance of this. That suggests that the meaning of your message in that section is getting lost in amongst all the words. When I was writing a column for JavaWorld my editor was really good at helping me eliminate any words in my columns that were not part of the message. She helped me understand that the fewer words you use to communicate a point, the more likely it is the point you are making will come across. In the paragraphs you've quoted you talk about no fewer than six concepts von-Neumann vs Harvard architecture, native word length vs byte length, instruction complexity vs word length, multiple cores vs single cores, volatility of RAM vs ROM, and oh by the way there are only 496 usable words of memory. I know it would help me if each concept was covered separately rather than all at once as that would help me absorb each concept better, if they built one upon the other even better. I do appreciate the time and effort you put into getting all of this information into a single document too!
--Chuck
- They miss manpower
- They know it will not boost business to teach some hard boiled newbies
- They think there is enough information available.
These are guesses...
When I wrote the Tutorial half a year ago it was done on request of a very specific group, who also requested a little bit of entertainment... And I worked under the false preconception, that everybody here had sufficient experience in SPIN and a working basis with the Propeller, so PASM would be the second step.
I would do it differently today: I would write a book for the half-wit, starting at least from Adam and Eve....Or I wouldn't I'm sure...
There is an excellent book about all the Propeller by Andr
=========================================================
It is obvious that you are a trained technical writer. I am not. I am a frustrated entertainer.
=========================================================
I (OZ)thought you were a German Shepherd..now this is a double fronted joke ...
A shepherd is a kind person that looks afer his flock...
+
Awhile ago you mentioned that sometimes your on your knees and you pretend to be a canine...
Sorry guy's could not resists it...
Relax a little deSilva.. you take it all too serious.. we appreciate what your doing but the "Body Language"
in your messages has the feel that your a little frustated..and you confirmed that yourself.
Take care
Ron Mel OZ
1) every memory location in a cog is a register
2) which can be referred to by either its address or a label
3) which may hold code or data
4) which may be modified by your program
5) and can be meaningfully reprogrammed with the MOVS, MOVD and MOVI commands.