*-------------------------------------
* 8 bit multiply and divide routines.
* Three 8 bit locations
* ACC, AUX and EXT must be set up,
* preferably on zero page.
*-------------------------------------

* MULTIPLY ROUTINE

* ACC*AUX -> ACC,EXT (low,hi) 16 bit result

MULT      LDA #0
          LDY #$09
	  CLC
:LOOP     ROR
          ROR ACC
          BCC :MUL2
          CLC		;DEC AUX above to remove CLC
          ADC AUX
:MUL2     DEY
          BNE :LOOP
          STA EXT
          RTS

* DIVIDE ROUTINE

* ACC/AUX -> ACC, remainder in EXT

DIV       LDA #0
          LDY #$08
:LOOP     ASL ACC
          ROL
          CMP AUX
          BCC :DIV2
          SBC AUX
          INC ACC
:DIV2
          DEY
          BNE :LOOP
          STA EXT
          RTS
