Re: LZ: Math question


[Prev][Next][Index][Thread]

Re: LZ: Math question



I am really sorry if this is sent to the list three times now, but
apparently I got bumped off the list somehow and I don't know if the
other two got through.  If this is sent multiple times then, "Build a
bridge and GET OVER IT!" -- someone at my church.
---
On Wed, 18 Jun 1997 23:43:49 -0500 Buddy Smith <ti85calc@bellsouth.net>
writes:
>Does anyone know of a way to multiply two numbers in ASM?

Sure! The following program multiplies two unsigned 16 bit integers and
leaves the result in the HL register pair.:

MULT:;   Unsigned 16 bit integer multiply.
;        On entrance: Multiplier in DE.
;        Multiplicand in HL.
;
;        On exit: result in HL.
;
;
;        Register uses:
;
;        H   High order partial result
;        L   Low order partial result
;        D   High order multiplicand
;        E   Low order multiplicand
;        B   Counter for number of shifts
;        C   High order bits of multiplier
;        A   Low order bits of multiplier
;
       LD  B,16;       Number of bits-initialize
       LD  C,D;        Move multiplier
       LD  A,E;
       EX  DE,HL;      Move multiplicand
       LD  HL,0;       Clear partial result
MLOOP: SRL C;          Shift multiplier right
       RRA;            Least significant bit is
;                      In carry.
       JR  NC,NOADD-$; If no carry, skip the ADD.
       ADD HL,DE;      Else ADD multiplicand to
;                      Partial result.
NOADD: EX  DE,HL;      Shift multiplicand left
       ADD HL,HL;      By multiplying it by two.
       EX  DE,HL;
       DJNZ MLOOP-$;   Repeat until no more bits.
       RET;
       END;


I hope this helps.


Sincerely,
The Unibomer

Jared Ivey
Unibomer@Juno.com
Ham Call Sign: KF4BXL
The Unibomer's Shack:
     http://www.geocities.com/SiliconValley/Vista/7342/
 _______________________
|  Florida Times Union  |
|=======================|
| Unibomer Strikes Again|
|   ~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~• |
|_______________________|


Follow-Ups: References: