After searching and unable to find any division or mod tables, decided to try my hand at creating them. The result is not what I expected. We are looking at 32 pages of tables just for 8-bit division and the max value for the dividend must also be 8-bit.
The code is written entirely in 6502, no monitor calls.
* Set up division table
DIV EQU $4 ; Dividend DR EQU $5 ; Divisor QUOT EQU $8 ; Quotient
ORG $300
LDA #01 STA $FE LDA #00 STA $FF
]LOOP INC $FF LDX #00 ]LRP LDY $FF ]LP LDA $FE L0310 STA $4000,X BNE L031D
CPY #03 BCS L031D DEY
L031D INX BEQ L0328 DEY BNE ]LP
INC $FE TXA BNE ]LRP
L0328 INC L0310+2 LDA #00 STA $FE LDY $FF CPY #$10 BNE ]LOOP RTS RTS ; filler byte so next routine falls on an even number at 820 ($334)
* To use POKE 4,DIV: POKE 5,DV: CALL 820: ? PEEK(8)
lda #00 sta $06
ldx $05 ; divisor dex lda table,x sta $07
ldy $04 ; dividend dey lda ($06),y sta $08 ; quotient rts
table hex 40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f
0300:A9 01 85 FE A9 00 85 FF E6 FF A2 00 A4 FF A5 FE 0310:9D 00 40 D0 05 C0 03 B0 01 88 E8 F0 08 88 D0 EE 0320:E6 FE 8A D0 E7 EE 12 03 A9 00 85 FE A4 FF C0 10 0330:D0 D6 60 60 A9 00 85 06 A6 05 CA BD 48 03 85 07 0340:A4 04 88 B1 06 85 08 60 40 41 42 43 44 45 46 47 0350:48 49 4A 4B 4C 4D 4E 4F
1 REM DIV=DIVIDEND DV=DIVISOR 2 REM FOR THIS TABLE, PEEK (8) IS THE QUOTIENT 10 DIV = 249 20 FOR DV = 1 TO 8 : GOSUB 30: NEXT : END 30 PRINT DV ": "DIV / DV " " 40 POKE 4,DIV: POKE 5,DV: CALL 820 50 ?"The QUOTIENT of "PEEK(4)" / "PEEK(5)" = " PEEK (8) 60 RETURN
* Set up MOD tables DIV EQU $4 ; Dividend DR EQU $5 ; Divisor QUOT EQU $8 ; Remainder
ORG $300
lda #$40 sta $07 lda #00 sta $06
ldx #$10 ldy #00 ]lp sta ($06),y iny bne ]lp inc $07 dex bne ]lp
lda #01 sta $ff
]lrp ora #$40 sta $07
ldy #01 sty $fe
inc $ff ldx $ff stx $fd dex
]loop ldy $fd
]lp lda $fe sta ($06),y clc tya adc $ff tay bcc ]lp
inc $fd inc $fe dex bne ]loop
lda $ff cmp #$10 bcc ]lrp rts
hex 00,00,60 ; filler bytes so next routine falls at 840 ($348)
* To use POKE 4,DIV: POKE 5,DV: CALL 840: ? PEEK(8)
lda #0 sta $06
ldx $05 dex lda table,x sta $07
ldy $04 dey lda ($06),y sta $08 rts
table hex 40,41,42,43,44,45,46,47,48,49,4a,4b,4c,4d,4e,4f
0300:A9 40 85 07 A9 00 85 06 A2 10 A0 00 91 06 C8 D0 0310:FB E6 07 CA D0 F6 A9 01 85 FF 09 40 85 07 A0 01 0320:84 FE A6 FF E8 86 FD CA E6 FF A4 FD A5 FE 91 06 0330:18 98 65 FF A8 90 F5 E6 FD E6 FE CA D0 EC A5 FF 0340:C9 10 90 D6 60 00 00 60 A9 00 85 06 A6 05 CA BD 0350:5C 03 85 07 A4 04 88 B1 06 85 08 60 40 41 42 43 0360:44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 00 00 00 00
1 REM DIV=DIVIDEND DV=DIVISOR 2 REM FOR THIS MOD TABLE, PEEK (8) IS THE REMAINDER 10 DIV = 249 20 FOR DV = 1 TO 8 : GOSUB 30: NEXT : END 30 X= INT (DIV / DV): PRINT DV ": "DIV - DV * X " "; 40 POKE 4,DIV: POKE 5,DV: CALL 840 50 ?"The MOD of "PEEK(4)" / "PEEK(5)" = " PEEK (8) 60 RETURN
|