Shorthand syntax questions. Having trouble
zongo
Posts: 2
Hello All,
I have attached a file that can also be found at
http://obex.parallax.com/objects/138/
I set up the circuit and it works just fine, but now I want to understand the programming.
The attachment is a bundle of files from the obex file cited above. (I included them all because it might help someone answer my question.)
The specific file that contains code lines I cannot understand is the file
CD_LTC1298.spin
These code lines are part of a repeat loop, but I just have the offending lines here so you can see what I mean.
datar |= |< i ' set bit i HIGH
datar &= !|< i ' set bit i LOW
Is that shorthand?
If so, can someone tell me what the "longhand" would be for an equivalent statement?
I think it says something about comparing "datar" with ORs and ANDS, and then doing some bitwise operations but I am lost from there.
I do know that the loop this code is located spits out the 12bit ADC data from each channel from a 2-channel ADC.
Thanks,
zongo
I have attached a file that can also be found at
http://obex.parallax.com/objects/138/
I set up the circuit and it works just fine, but now I want to understand the programming.
The attachment is a bundle of files from the obex file cited above. (I included them all because it might help someone answer my question.)
The specific file that contains code lines I cannot understand is the file
CD_LTC1298.spin
These code lines are part of a repeat loop, but I just have the offending lines here so you can see what I mean.
datar |= |< i ' set bit i HIGH
datar &= !|< i ' set bit i LOW
Is that shorthand?
If so, can someone tell me what the "longhand" would be for an equivalent statement?
I think it says something about comparing "datar" with ORs and ANDS, and then doing some bitwise operations but I am lost from there.
I do know that the loop this code is located spits out the 12bit ADC data from each channel from a 2-channel ADC.
Thanks,
zongo
zip
35K
Comments
datar &= !|< i is the same as datar := datar & !(1 << i)
-Phil
datar |= |< i ' set bit i HIGH
datar &= !|< i ' set bit i LOW
The |=·operator (Or-Assign) does two things it ORs the left operand with the right operand
and then it assigns the result to the left variable.
So datar |= 5·· will OR datar with the number 5 and the result will be put back into the
variable datar.
now the |< operator·puts a 1 in·one of the·bits of a 32-bit number Zero. Which bit is defined by the number on the right
of the operator. So when you say |< 9 then you will have a 32 bit number with all Zeros in all bits except in bit 9.
so datar |= |< i
will create a number with all bits of 0 except the ith bit set to 1
it will then OR datar with that number
it will then put the result back into datar
The resulting outcome is that the ith bit in the value of the number stored in the variable datar has been turned ON.
The next line is doing a similar thing but it ANDs (the &= is the AND-Assign operator) the ith bit with a 0 which turns it off.
This is achieved by inverting the result of the |< i· using the ! operator which is called the NOT operator which basically
inversts all the bits of the number.
So then if we·invert a 32 bit number with all bits as 0 except for the ith bit, we end up with a number with all the
bits as 1 except for the ith bit as 0.
Remember when you OR with 1 you get 1· and when you AND with 0 you·get 0.
Regards
Samuel
Post Edited (SamMishal) : 9/23/2009 5:34:50 AM GMT
This may be exactly what I need.
Oh, Anyone know of a quick reference guide that has good, concise synopses on shorthand (the commands...a single example for each, etc.)?
Currently reading the manual and PE Fundamentals, but the closest thing to what I want is the parallax Quick Reference for spin and assembly. All are very helpful, but not the distillation I need.
Thanks again, I can now continue figuring the rest of the method.
zongo
to play!
Ken
The best reference to all the operators and a VERY GOOD description of how they
work etc. is in the Propeller Manual. Section called Operators on Page 143 to 174 of
the version 1.1 manual.
It is 32 pages of GOOD information and the table given on page 144 and the other
on page 145 are good quick reference you should copy them and put them in a handy
place for Quick Reference.
I think once you read these 32 pages you should be OK.
Regards
Samuel
Post Edited (SamMishal) : 9/23/2009 5:34:37 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade, RetroBlade,·TwinBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
One of the things I really like about the prop is the mix n match with spin/machine code. Coming from a Z80/8080/Pic background, I find machine instructions easier to understand but that is just a personal preference. It is amazing what you can do with just 4 prop machine instructions -
AND ' logical and
OR ' logical or
SHL ' shift left n bits
SHR ' shift right n bits
I find these instructions self explanatory, although it never hurts to have the binary values before and after as a comment.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/build
Sometimes I think there is more truth in this than I would like to believe.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade, RetroBlade,·TwinBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
I started writing a book called Supermodel Programming. I figured if I could teach a Supermodel (Tyra Banks, etc...) how to program, I could teach anyone. My daughter pointed out that Supermodels wouldn't even be thinking about writing programs, so I would be wasting my time ... I reluctantly agreed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools
- Propalyzer: Propeller PC Logic Analyzer
- BMA: An on-chip PASM Debugger
- SPUD: Spin Source Level Debugger
Post Edited (jazzed) : 9/23/2009 1:22:27 PM GMT