Re: A85: Help! :)


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

Re: A85: Help! :)




On Sat, 26 Sep 1998 DorkReMi@aol.com wrote:

> 
> I could use a little guidance... I need 16 bit math routines (B*C, H*L, that
> kind of thing) and I don't know where to get them. Also, I could really use a
> good random number routine. Was there one in ztetris or something?  Thanks for
> any advice.
> 
> -Josh Morris
>  DorkReMi@aol.com
> 
Here's HL = H * L

MulHL:
  ld a,0
  ld b,8
Loop:
  bit 0,l
  jr nz,NoAdd
  add a,h
NoAdd:
  srl a
  rr l
  djnz Loop
  ld h,a
  ret

destroys a of course.
what kind of division were you looking for?  DE/HL or something?  The
division algorithm I used for my 32-bit routines required 3 Registers.
Here's a conversion:

BC = HL / DE  HL = HL % DE  DE=DE

DivHLDE:
  ld a,0
  cp h
  ret z
  cp l
  ret z
  inc a
  or a
DivLoop1:
  bit 7,d
  jr nz,DivLoop2
  inc a
  sla e
  rl d
  jr DivLoop1
DivLoop2:
  call CP_HL_DE		;does this destroy a? if so you need to save a
  jr c,DivNoSub
  or a
  sbc hl,de
DivNoSub:
  ccf
  rl c
  rl b
  sra d
  rr e
  dec a
  jr nz,DivLoop2
  rl d
  rl e
  ret

I haven't tested it but it works for my 32-bit routine.

Sorry for the wait, later.

-Humberto Yeverino Jr.

"I kick ass for the Lord."

***********************************************************
Home Page:                                               
  http://www.engr.csufresno.edu/~humberto/Home.html      

Ti Page:                                                 
  http://www.engr.csufresno.edu/~humberto/tex.html       

z80 Source Page:                                         
  http://www.engr.csufresno.edu/~humberto/z80source.html 

Official Tyrant Home Page:                              
  http://www.engr.csufresno.edu/~humberto/tyrant.html    

E-mail:                                                  
  humberto@engr.csufresno.edu                            
***********************************************************


References: