home *** CD-ROM | disk | FTP | other *** search
- DVSOR RMB 3 24 bit divisor
- DVDND RMB 3 24 bit dividend (entry) - result (exit)
- TEMPA RMB 1
- TEMPB RMB 1
- COUNT RMB 1
- TEMP1 RMB 1
- TEMP2 RMB 1
- TEMP3 RMB 1
- TEMP4 RMB 1
- OCRH RMB 1
- OCRL RMB 1
- ALTCNTH RMB 1
- ALTCNTL RMB 1
-
-
- **** 16 BITS / 16 BITS = 16 BITS DIVISION subroutine ****
- * *
- * on entry : DVDND DVDND+1 = dividend *
- * DVSR DVSR+1 = divisor *
- * on exit : DVDND DVDND+1 = quotient *
- * (MSByte first - Motorola style) *
- *********************************************************
- DIV1616 LDA #1
- TST DVSOR
- BMI DIV153
- DIV151 INCA
- ASL DVSOR+1
- ROL DVSOR
- BMI DIV153
- CMP #17
- BNE DIV151
- DIV153 STA COUNT
- LDA DVDND
- LDX DVDND+1
- CLR DVDND
- CLR DVDND+1
- DIV163 STA TEMPA
- TXA
- SUB DVSOR+1
- TAX
- LDA TEMPA
- SBC DVSOR
- BCC DIV165
- STA TEMPA
- TXA
- ADD DVSOR+1
- TAX
- LDA TEMPA
- ADC DVSOR
- CLC
- BRA DIV167
- DIV165 SEC
- DIV167 ROL DVDND+1
- ROL DVDND
- LSR DVSOR
- ROR DVSOR+1
- DEC COUNT
- BNE DIV163
- RTS
-
-
- **** 24 BITS / 24 BITS = 24 BITS DIVISION subroutine ****
- * *
- * on entry : DVDND DVDND+1 DVDND+2 = dividend *
- * DVSR DVSR+1 DVSR+2 = divisor *
- * on exit : DVDND DVDND+1 DVDND+2 = quotient *
- * (MSByte first - Motorola style) *
- * 3055 cycles worst case time (0/1) *
- * *
- *********************************************************
-
- DIV2424 LDA #1
- TST DVSOR divisor < 0 ?
- BMI DIV233 |
- DIV231 INCA
- ASL DVSOR+2 move DVSOR's msb full left rotating
- ROL DVSOR+1 it left COUNT times
- ROL DVSOR |
- BMI DIV233 |
- CMP #25 |
- BNE DIV231 |
- DIV233 STA COUNT |
- LDA DVDND+2 Save dividend in TEMPB,A,X
- STA TEMPB and clear dividend area to store result
- LDA DVDND |
- LDX DVDND+1 |
- CLR DVDND |
- CLR DVDND+1 |
- CLR DVDND+2 |
- DIV243 STA TEMPA Subtract left-shifted divisor
- LDA TEMPB from dividend
- SUB DVSOR+2 |
- STA TEMPB |
- TXA |
- SBC DVSOR+1 |
- TAX |
- LDA TEMPA |
- SBC DVSOR |
- BCC DIV245 Divisor OK? (i.e. < dividend)
- STA TEMPA Divisor too large :
- LDA TEMPB Add divisor back to the result of the
- ADD DVSOR+2 previous subtraction and shift a '0'
- STA TEMPB in the quotient (CLC, ROL)
- TXA |
- ADC DVSOR+1 |
- TAX |
- LDA TEMPA |
- ADC DVSOR |
- CLC |
- BRA DIV247
- DIV245 SEC If divisor OK, shift '1' in quotient
- DIV247 ROL DVDND+2 Rotate result
- ROL DVDND+1 |
- ROL DVDND |
- LSR DVSOR Shift divisor
- ROR DVSOR+1 |
- ROR DVSOR+2 |
- DEC COUNT End of loop?
- BNE DIV243
- RTS
-
-
- *************** OCF timer update subroutine *************
- * *
- * on entry : X reg = byte to add to OCRL *
- * (output compare low reg) *
- * on entry : A reg = byte to add to OCRH *
- * (output compare hi reg) *
- * each added bit = 4 cycles - 2 microsec @4MHz *
- * *
- * subroutine max exec time:24 cycles(inc return) *
- * +10 parm. setup and call *
- * (17 microsec @4MHz) *
- *********************************************************
-
- OCTUPD ADD ALTCNTH read alternate timer counter hi: this
- STA OCRH freezes ALTCNTL. Then store in OCRH:
- TXA o.c. interrupts inhibited until OCRL is
- ADD ALTCNTL written. If carry from lower bytes,
- BCC NOCARRY increment OCRH.
- INC OCRH
- NOCARRY STA OCRL
- RTS
-
- **** 16 BITS / 16 BITS = 32 BITS MULTIPLY subroutine ****
- * *
- * on entry:[1,DVDND:2,DVDND]=[MPCAND:1,MPCAND]=[X:1,X] *
- * =MULTIPLICAND *
- * [2,DVSOR:DVDND]=[MPLIER:1,MPLIER]= *
- * =MULTIPLIER *
- * on exit:[DVSOR:DVDND]=[M16RES:3,M16RES]= *
- * =32 bit RESULT *
- * (MSByte first - Motorola style) *
- * *
- *********************************************************
- MULT16 CLR TEMP1
- CLR TEMP2
- LDA #16
- STA TEMPA
- CLC
-
- M16LOOP ROR TEMP3
- ROR TEMP4
- BCC MLOOP5
- LDA TEMP2
- ADD 1,X
- STA TEMP2
- LDA TEMP1
- ADC 0,X
- STA TEMP1
-
- MLOOP5 ROR TEMP1
- ROR TEMP2
- DEC TEMPA
- BNE M16LOOP
- ROR TEMP3
- ROR TEMP4
- RTS
-