Announcement

Collapse
No announcement yet.

Basic code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Steve Hutchesson
    replied
    You are probably right John, I do a quick & dirty int multiply
    this way,

    Code:
    IntMul proc source :DWORD,multiplier :DWORD
      
        LOCAL var1 :DWORD
      
        fild source         ; load source
        fild multiplier     ; load multiplier
        fmul                ; multiply source by multiplier
        fist var1           ; store result in variable
        mov eax, var1
      
        ret
      
    IntMul endp
    It translates directly to PowereBASIC inline with no problems.

    Still, ther are a lot of the old timer tricks that are worth
    knowing so Bucks technique may be of some use when approaching
    integer multiply without FP instructions.

    Regards,

    [email protected]

    [/CODE]

    ------------------


    [This message has been edited by Steve Hutchesson (edited March 30, 2001).]

    Leave a comment:


  • Lance Edmonds
    replied
    Those, and the other UUB formatting options for the BBS, are detailed at http://www.powerbasic.com/support/forums/ubbcode.html which appears in a link next to all "reply" boxes...

    Likewise, the smilies legend can be found at: http://www.powerbasic.com/support/forums/smilies.html

    I hope this helps!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Buck Buchanan
    replied
    Wayne,

    Use " [ code ] and [ /code ] ", you say... hmmm.... very
    intuitive. Wonder why I didn't think of that...

    Buck

    Leave a comment:


  • John Petty
    replied
    Hutch
    Only looks cute in decimal, shift and add if 1 is how its done in most CPU's unless the have a dedicated flash multiplier.
    The only reason the standard instruction would be slow is due to using 2 registers for the result.
    Pity Intel doesnt have an instruction which does an integer multiply resulting with a long in EAX



    ------------------

    Leave a comment:


  • Steve Hutchesson
    replied
    Thats a rather cute technique Buck, I will have to remember that
    one for integer multiplication in assembler as multiply is very
    slow in integer instructions.

    Regards,

    [email protected]

    ------------------

    Leave a comment:


  • Wayne Diamond
    replied
    Buck, use [ code ] and [ /code ] statements (without any spaces) to format with fixed-width fonts, eg:
    Code:
    sweet huh?  

    ------------------

    Leave a comment:


  • Buck Buchanan
    replied
    The column of numbers in my previous post should be right
    justified... I didn't realize that the msg base would move
    everything over to the left... grrr! computers and their
    formatting.

    Buck

    Leave a comment:


  • Buck Buchanan
    replied
    Manuel,

    I'll leave the writing of the code to you, but here is an example
    of adding to achieve multiplying. Let's multiple 126 times 624.

    126
    x 624
    -----

    First add 126 4 times.
    Now add 1260 2 times.
    and now add 12600 6 times.

    The addition problem would look something like this:

    126
    126
    126
    126
    1260
    1260
    12600
    12600
    12600
    12600
    12600
    12600
    --------
    78624
    ========

    Before the days of calculators, this is the way that we had
    to multiply on an adding machine... hope that this gets you
    started.

    Buck

    p.s. Geezzz! did I date myself a little or what...

    Leave a comment:


  • Tom Hanlin
    replied
    Hmmm... is this a school assignment? Perhaps you should do it on your own?

    I think it should be simple enough to add by adding, and subtract by subtracting,
    unless your question left out something important?

    Multiplication by addition, well. x * y is the same as x added to itself y times,
    is it not? Likewise, x / y is about the same as subtracting y from x until y is
    less than x...

    I think there are BCD examples of handling this sort of issue in the PBWiz library
    from Information Management Systems, if you need working code. See www.infoms.com
    for details.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Fred Oxenby
    replied
    you only need shift,add and XOR to perform add/subtract/multip./divide


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Basic code

    Basic code

    Can anybody help me write code to add, substract, multiply and divide using add and substract statements only ??

    Thanks

    ------------------
Working...
X