Searching \ for 'Representing numbers (24-bit)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=representing+numbers
Search entire site for: 'Representing numbers (24-bit)'.

Truncated match.
PICList Thread
'Representing numbers (24-bit)'
2000\03\19@034936 by Saurabh Sinha

picon face
part 0 16 bytes
</x-html>

2000\03\19@043413 by Victor Marinov

flavicon
face
part 0 16 bytes
</x-html>

2000\03\19@160105 by paulb

flavicon
face
> Saurabh Sinha wrote:

> clrf prod1;
> clrf prod2;
> clrf prod3;

> prod1 equ 00001101;
> prod2 equ 10010100;
> prod3 equ 11001011;

 The assembler wont let you do that.  Using "equ" allocates a value to
the variable name.  If you subsequently use that variable name, you will
be referencing a memory location whose address is the value you
allocated.  You will encounter two faults as a result, firstly that you
have tried to clear memory locations before you told the compiler where
the locations were, and also that the second and third locations are
neither directly accessible, nor exist as memory.

> Sorry, I am new at programming.

 Before attempting to start with your own project, it will be necessary
to study and work through, a *lot* of examples.  Look up James Newton's
site.

> these numbers have in common are that they are mulitples of each
> other, say: c1=(1/(3*pi))*2^16, c2=(1/(6*pi))*2^16. Is there any way I
> can take advantage of this fact, perhaps to save some space?

 Where they are related by powers of two, you can by performing simple
rotates to divide or multiply by two.
--
 Cheers,
       Paul B.

2000\03\20@034115 by Nikolai Golovchenko

flavicon
face
On Sunday, March 19, 2000 Saurabh Sinha wrote:
> Hi,

> I need some help in representing 24-bit numbers on the 16F84.

> Say the number is: 00001101 10010100 11001011

> Then, can I use:

> clrf prod1;
> clrf prod2;
> clrf prod3;

> prod1 equ 00001101;
> prod2 equ 10010100;
> prod3 equ 11001011;

> This is the only way, right? (Sorry, I am new at programming.)

Nope. You can use a couple of ways to do this:
#define prod24 0x823456

       movlw (prod24 >> 16)            ;high byte
       movlw ((prod24 >> 8) & 0xFF)    ;middle byte
       movlw (prod24 & 0xFF)           ;low byte

For 16bit number:
#define prod16 0xFEAB

       movlw low(prod16)       ;low byte
       movlw high(prod16)      ;high byte

Read about this kind of things in MPASM manual

> Okay, another question: I don't just have to represent 1-24 bit
> number, but 10 24-bit numbers, what these numbers have in common are
> that they are mulitples of each other, say: c1=(1/(3*pi))*2^16,
> c2=(1/(6*pi))*2^16. Is there any way I can take advantage of this
> fact, perhaps to save some space?

Probably. There are some limitations however: constants are treated as
integers (maximum 32 bits) in MPASM, so fraction part is truncated,
and you can't use floating point constants.

For example,
#define c1 (695358557 / 100000)
#define c2 (c1 / 2)

> Thanks in advance for your help.

> Regards,

> Saurabh

Hope it helps.
Nikoai

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...