Div32


Closed Thread
Results 1 to 6 of 6

Thread: Div32

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Div32

    Hello Everyone,
    Still in an effort to understand this programming language, I now am playing with DIV32.
    I have taken the code from the manual and added some serial routines so I can view whats happening. I have posted the code below.
    Code:
    ' Use MPASM
    @MyConfig = _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _LVP_OFF 
    @MyConfig = MyConfig  & _CP_OFF & _BODEN_OFF & _DATA_CP_OFF
    @ __config  MyConfig
    Define PIC16F628A
    define OSC 20
    include "modedefs.bas"
    
    
    a     var word
    b     var word
    c     var word
    Dummy var word
    start:
     b = 500
     c = 1000
     
     disable ' 
     
     dummy = b * c
     a = div32 100
    
     enable
     serout PortB.4,T9600,[254,1]
     pause 100
     serout PortB.4,T9600,[254,128,"dummy is:",# Dummy]
     pause 1000
     serout PortB.4,T9600,[254,192,"A is:", # a]
     pause 1000
     serout PortB.4,T9600,[254,148,"B is:", # b]
     pause 1000
     serout PortB.4,T9600,[254,212,"C is:", # c]
     pause 1000
     goto start
    end
    The code does what the book says it should do. I have a couple of questions:
    the line, a = DIV32 100 . I get that the 100 causes DIV32 to divide by 100, what I do not get is how DIV32 knows to use the math in the above formula, is "Dummy " a default place holder? My second question is the value of Dummy as outputted in line 1 of the display, I get the fact, 5 hundred thousand is too large for 16 bits to hold but 41248 makes no sense to me, can anyone explain?
    Thank You
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Windows Calc commes pretty handy in this case... 500,000=07 A1 20 hex right?

    As Dummy is a WORD, it keep only A1 20, witch equate to 41248.

    you could still use
    Code:
     A = b * c
     a = div32 100
    or
    Code:
     B = b * c
     B = div32 100
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Windows Calc commes pretty handy in this case... 500,000=07 A1 20 hex right?
    Thank You Mister_e, that leads me into another question:
    I thought microprocessors worked only in binary, logic high and logic low, so why do we use hex anyway? Is it because we have 16 bits?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Why decimal, why Hex, why Octal and why Binary... it's just different measure like Km/h Mph, Mils or mm, Yard Meter.

    In the previous, it's easier to figure out the problem with Hex than Decimal. A word is indeed 16 bits (uh...). PBP don't have any LongWord or DoubleWord var, DIV32 work around that.

    Bad explanation i know... It's clear in my little head, but right words won't go out
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Hey Joe,
    Have a look at Darrel's Threads using DIV32 and other 32 bit math magic. Good stuff from the Wizard.
    Retrieving 32bit Multiply Result
    Retrieving Div32 Remainder
    32-bit Variables and DIV32, Hourmeter 99999.9


    SteveB

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Thanks.
    Iwill look at those threads too.
    Joe

    Edit:Those are great, I have bookmarked these pages and stashed the code samples for study.
    Last edited by Archangel; - 2nd February 2007 at 23:33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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. 32-bit Variables and DIV32, Hourmeter 99999.9
    By Darrel Taylor in forum Code Examples
    Replies: 9
    Last Post: - 23rd November 2006, 07:23
  5. Retrieving Div32 Remainder
    By Darrel Taylor in forum Code Examples
    Replies: 4
    Last Post: - 20th August 2003, 03:53

Members who have read this thread : 2

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

Posting Permissions

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