Shop OBEX P1 Docs P2 Docs Learn Events
Beginner - Help with 32 bit sums — Parallax Forums

Beginner - Help with 32 bit sums

algorhythmalgorhythm Posts: 4
edited 2005-01-16 02:37 in General Discussion
I'm trying to construct a multiply-by-add-loop algorithm that combines two 16 bit numbers to create a 32 bit answer.

I can't figure out how to properly manipulate the fourth bit of the answer to get the correct result...
How do I make addition carry into the fourth bit?

//


multx ds 2
multy ds 2
product ds 4

init mov multx,#$50 ; $c350 = 50000
mov multx+1,#$c3 ;
mov multy,#$30 ; $7530 = 30000
mov multy+1,#$75 ;

multiply
clr product
clr product+1
clr product+2
clr product+3
:loop
add product,multx
addb product+1,c
add product+1,multx+1
addb product+2,c
addb product+3,c ; How should I treat the fourth bit?
djnz multy,:loop
djnz multy+1,:loop

Comments

  • KenMKenM Posts: 657
    edited 2005-01-15 05:45
    Yeah,

    Binary math is pain for me also

    www.sxlist.com

    32 bit binary addition

    Translated and optimized for the Scenix SX by Nikolai Golovchenko

    From: Regulus Berdin mov W, term0 add prod0, W mov W, term1 snb C movsz W, ++term1 add prod1, W mov W, term2 snb C movsz W, ++term2 add prod2, W mov W, term3 snb C movsz W, ++term3 add prod3, W

    Ken
  • algorhythmalgorhythm Posts: 4
    edited 2005-01-16 02:37
    Cool.

    Thanks for the code and link. Exactly what I needed.

    - a
Sign In or Register to comment.