View previous topic :: View next topic |
Author |
Message |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
Instruction |
Posted: Tue Mar 06, 2012 5:45 am |
|
|
I want to understand the meaning of these instructions (I want a simple and clear explanation) :
1 :
Datas = matris [(0),(1)]&(0x01)
means : matris [(0),(1)] = 0x49 .
which implies : Datas = 0x49 & 0x01 , this formula gives us any result ?
2:
i<<1 !!??
Thank's. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Mar 06, 2012 6:06 am |
|
|
press F11 while your project is open.... |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Mar 06, 2012 6:07 am |
|
|
& is the bitwise boolean and operator.
c = a & b;
means and together the bits of a and b and put the result in c.
Example:
c = 0x49 & 0x01;
which for 8 bit integers is the same as
c = 0b01001001 & 0b00000001;
c will be 0b00000001.
Most processors can do logical ands in single instructions on its native word width. For 16 and 18 PICs that means 8 bits.
Ands, and the related or, |, and exclusive or, ^, are often used in setting, clearing and inverting bits and bit patterns.
<< is the logical left shift operator.
c = a << 3;
means left shift (i.e. towards the most significant bit) three bits and put the result in c.
Example:
c = i << 1;
where c and i are 8 bit integers and i is 3 (i.e. 0b00000011). c will be 6, or 0b00000110. For unsigned integers shifting left one bit in the same as multiplying by two. With signed integers it may not be if the value being shifted is negative.
Shifts are often used to isolate single bits in bit patterns, and for multplying and dividing by powers of two.
Most processors can do logical shifts in single instructions. There is also the right shift, >> in C. Arithmetic shifts are often available in many instruction sets, though NOT in C. Arithmetic shifts preserve the sign bit and so can be used for multiplying and dividing by powers of two on signed variables. Also some processors provide rotates, which are shifts via an extra bit, usually the carry bit in the processor status word. Rotates allow bits to be shifted out but not lost (the previous content of carry is shifted into the other end of the variable). Generally these are useful to test each bit of a variable in turn while preserving the value of the variable if you shift by the number of bits. Combinations of rotates and shifts allow mutlilength shifts to be carried out on short word length processors, e.g. 16 and 32 bit shifts on 8 bit processors. Rotates are not part of C.
Shifts and ands/ors are ofte used together. As in
if ((a = a >> 1) & 0x01)
{
// Do stuff if the least significant bit of a was one after shfiting it one bit to the right.
}
All standard basic logical operators in C.
RF Developer. |
|
|
kamillas
Joined: 24 Oct 2011 Posts: 50
|
& |
Posted: Tue Mar 06, 2012 9:11 am |
|
|
this formula and what it gives results ?
Code: | datas=Matris2[0][1]&K; |
knowing that :
Matris2[0][1]= 0x7F and K= 0X01 |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 06, 2012 10:23 am |
|
|
"datas" will be an int1
that is determined by the LOW order bit of the array element you are indexing.
this is very very basic C that we are talking about here, and not the least bit CCS specific . |
|
|
kamillas
Joined: 24 Oct 2011 Posts: 50
|
OK |
Posted: Tue Mar 06, 2012 11:08 am |
|
|
asmboy wrote: | "datas" will be an int1
that is determined by the LOW order bit of the array element you are indexing.
this is very very basic C that we are talking about here, and not the least bit CCS specific . |
means that :
#define datas RA_0
datas = Matris2[0][1]= 0x7F&0X01 = (01111111)&0x01 = 1 (the bit low order selected in bold ). |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 06, 2012 12:06 pm |
|
|
Quote: |
means that :
#define datas RA_0
|
if by this you believe that this will then control the OUTPUT state
of PIN_A0 - you are in for a surprise and NOT a pleasant one at that.
you might have better luck with
output_bit( PIN_A0, 1_bit_result_of_your evaluation);
or a better crafted #bit directive |
|
|
kamillas
Joined: 24 Oct 2011 Posts: 50
|
No |
Posted: Tue Mar 06, 2012 2:36 pm |
|
|
asmboy wrote: | Quote: |
means that :
#define datas RA_0
|
if by this you believe that this will then control the OUTPUT state
of PIN_A0 - you are in for a surprise and NOT a pleasant one at that.
you might have better luck with
output_bit( PIN_A0, 1_bit_result_of_your evaluation);
or a better crafted #bit directive |
no , datas to control a serial register Parallel such as 74hc595 |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Mar 06, 2012 3:01 pm |
|
|
Quote: |
datas to control a serial register Parallel such as 74hc595
|
actually makes no sense as written.
"CONTROL" WHAT aspect of the /595 ??
are you now trying to say that your understanding of circuit design is
(A)
better
or
(B) worse
than your comprehension of of 'C ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Mar 06, 2012 3:09 pm |
|
|
flip of a coin ! heads,tails, edge...tri-state !!!
I'm 'thinking' that 'datas' is the bit representation of the serial data that's going to go to a series of 595 chips for a 'scrolling LED display' school assignment.
It's just silly to not name variables better to self-represent what they are or do.It'd sure help break the language barrier |
|
|
|