Cant input or output greater than 9 bits
Sorry for the newbie question,
I have an 8 way DIP switch connected to P0 through P7, I also have 8 LED's connected to P16 through P23. All I wish to do is read the DIP switch and display its current setting on the LED's.
I am failing at the first hurdle as I cant even set the DIRA up as when I try to "mov dira, %00000000111111110000000000000000" I get a compiler error telling me the source cannot be greater than $1FF.
My question then is how in assembler can I set the upper bits of DIRA, INA or OUTA when I can only use 9 bits in the source?
In spin I can just do "DIRA := %00000000111111110000000000000000"
I have an 8 way DIP switch connected to P0 through P7, I also have 8 LED's connected to P16 through P23. All I wish to do is read the DIP switch and display its current setting on the LED's.
I am failing at the first hurdle as I cant even set the DIRA up as when I try to "mov dira, %00000000111111110000000000000000" I get a compiler error telling me the source cannot be greater than $1FF.
My question then is how in assembler can I set the upper bits of DIRA, INA or OUTA when I can only use 9 bits in the source?
In spin I can just do "DIRA := %00000000111111110000000000000000"
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
you could do :-
the # signifying that you want to use a literal value and not a pointer to a value at a cog-ram address.
But as you want to set higher than bit 9, you have to use a pointer, as Ale demo'd
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
Welcome to the Forum!
I'm typing this in real-time and only have a few minutes. PLEASE propeller PASM experts
correct my mistakes (likely many). This is a subject that should be EXPLICIT in the
Propeller Manual IMHO; with lots of examples.
It's implicit with the "mov dira..." line in your post you're programming in Propeller Assembler
(PASM). Please read the Propeller Manual section regarding "Literals Must Fit in 9 Bits". I excerpt
from the Propeller Manual V1.1 (have on-hand in this machine right now).
"Literals Must Fit in 9 Bits
The source operand is only 9 bits wide; it can hold a value from 0 to 511 ($000 to $1FF).
Keep this in mind when specifying literal values. If a value is too big to fit in 9 bits, it must
be stored in a register and accessed via the register's address. For example: (ed. read the Manual)"
If you set a literal value greater than $1FF then you need to specify an initialized register that
can hold a long. A res declaration cannot exceed $1FF in size if memory serves (may be wrong
here).
All (initialized) long declarations MUST be on lines in DAT area before any res declares.
Again, Chris B...
When you post a question like this, please post your source code as well. This forum a
little broken wrt source code posts, so there is a tool to reformat your source that may
post better (thanks again Phil). Here's the link (also available via the unofficial Propeller Wiki).
www.phipi.com/format/
Read and contribute to the Propeller Wiki here (start page):
propeller.wikispaces.com/
How is RES different from LONG? (from the Propeller Wiki)...
A Must Read regarding your question IMHO.
propeller.wikispaces.com/LONG+vs+RES
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
jmp #Read
in it. With other data at the end you might have bad luck doing thing the COG should better not do!
Remember the COG is always loaded with 496 longs. If you have other PASM sections behind that one or if you did some SPIN stuff which used some stack space, the memory behind your PASM code will have content. Anything can happen then.
So, make sure you stay within a loop in your code or stop the COG when you're done.
This is the beginning of a bigger project to control a camera and flash but it is me dipping my big toe into assembler. I agree completely about the
jmp #Read
I was very surprised it continued to loop as that is not what I wanted, Ale has already given me the answer but I am still not sure as to why it does it. As I said I have only just dipped a toe in. I am sure there will be a lot more head banging before I am finished.
As I said you are lucky that nothing bad happens. If you would have some strings at the end of the dat section anything can happen. Setting input-pins to output in this COG is the worst, as it can destroy the IO-pins of the propeller. Overwriting HUB-RAM might have funny results as well - this could lead to problems in all other COGs.
Actually, the spin bytecode follows the DAT section, so the cog would have been loaded with "random" data comprising the spin bytecode, then the stack space (given the small example presented). So I am extremely surprised it made it all the way through more than once. I've almost never seen a cog loop around past the registers at the end anyway!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you always do what you always did, you always get what you always got.
Thinking about it, it makes sense this way. SPIN code is byte-code which can end at any RAM adress. Putting the PASM code behind it means that you can loose up to 3 bytes.
Dat, SPIN, Vars, Stack seems to be the right order. Well ... maybe the one SPIN instruction COGNEW has an opcode that does not harm or it might be a NOP. Maybe I'll check that this evening, if nobody else did before. But the point is ANYTHING can happen.