DIV32 Understanding


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2005
    Location
    Palmdale, CA
    Posts
    37

    Default DIV32 Understanding

    I have a problem I can't seem to figure out involving the DIV32 command. I am filling an array with 11 successive time measurements. I need to divide a large constant by each member of the array
    and output the result over a serial port to my PC.

    for i = 0 to 10
    velocity = speed[i]
    dummy = a * b 'RPM = 240000/velocity
    RPM = div32 velocity
    speed[i] = RPM
    next i
    for i = 0 to 10
    debug dec speed[i],", "
    next i
    debug 10,13

    goto main

    I tried to use:

    a con 240
    b con 1000

    and got screwy results.

    If I use:

    a var word
    b var word
    a = 240
    b = 1000

    I get the right answers.

    Why can't I multiply 2 constants together?

    I know there is a simple answer. I just don't see it

  2. #2
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    It may be best to simply follow the DIV32 "help" example as it is likely designed to use variables in place of constants in it's preceding line.

    Norm

  3. #3
    Join Date
    Jul 2005
    Location
    Palmdale, CA
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    Yes. The example is where I got the idea to use variables instead of constants. But my question is WHY can't constants be used.

  4. #4
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    Quote Originally Posted by enauman View Post
    Yes. The example is where I got the idea to use variables instead of constants. But my question is WHY can't constants be used.
    You are asking the inner workings of the compiler probably in assembly.
    Command DIV32 is unique as it is directly linked to its preceding line as part of the command.

    Norm

  5. #5
    Join Date
    Jul 2005
    Location
    Palmdale, CA
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    Maybe it should be called out in the command description. It's a trivial point. I was just curious.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    DIV32 requires certain system variables to have a 32-bit value in them.
    They are initialized by a multiplication operation with at least 1 word (the second value can be a constant).
    Then a library routine can be executed to do the multiplication.

    Part of the optimization of PBP is called "Constant Folding"
    If both values in the multiplication are constants ... the compiler multiplies them at "Compile-Time" and uses a single value (a constant).
    No multiplication is performed at run-time, and the system variables are never loaded with the 32-bit value.

    I've talked about DIV32 and the System vars it uses a few years ago ... http://www.picbasic.co.uk/forum/showthread.php?t=1942
    Last edited by Darrel Taylor; - 19th January 2013 at 06:53.
    DT

  7. #7
    Join Date
    Jul 2005
    Location
    Palmdale, CA
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    Thanks for the explanation Darrel. Exactly what I was looking for.

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: DIV32 Understanding

    Buuuuut ...

    The most charming girl this forum ever saw ( of course Melanie ! ) gave us long time ago the way to load those registers with a macro ... if my memory still works fine. AND ... I might still have a print of that ...

    Here's Darrel's edition : http://www.picbasic.co.uk/forum/showthread.php?t=1942 ...

    Alain
    Last edited by Acetronics2; - 19th January 2013 at 20:51.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Problem with Div32
    By lerameur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd April 2008, 02:54
  2. RPM - DIV32 Problem
    By davewanna in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th April 2008, 04:33
  3. DIV32 Questions ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th November 2007, 00:49
  4. Div32
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2007, 20:26
  5. DIV32 confusion
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th October 2005, 21:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts