base:8bit_logarithm_table_generator_routine
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:8bit_logarithm_table_generator_routine [2015-04-17 04:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 8bit log table generator ====== | ||
+ | Logarithm tables are often used in C64 and for much the same reason they were originally invented, that is exploiting the same identities your old slide rule uses for transforming multiplication and division into addition and subtraction:< | ||
+ | lg(x/y) = lg(x) - lg(y)</ | ||
+ | |||
+ | Yet they' | ||
+ | |||
+ | Note that the result is scaled to fit in eight-bits. This can most naturally be viewed a base-two logarithm in 3:5 fixed-point. | ||
+ | < | ||
+ | |||
+ | seed .byte $00,$00 | ||
+ | .byte $02,$05 | ||
+ | .byte $0c,$1f | ||
+ | |||
+ | reduce pla | ||
+ | adc seed,y | ||
+ | sec | ||
+ | next pha | ||
+ | ldy #5 | ||
+ | txa | ||
+ | sta shift+4 | ||
+ | |||
+ | shift ror shift+4 | ||
+ | sbx #$00 | ||
+ | bcs reduce | ||
+ | tax | ||
+ | dey | ||
+ | bpl shift | ||
+ | |||
+ | pla | ||
+ | store sbc #$1f | ||
+ | sta table | ||
+ | lsr store+3 | ||
+ | bcc store | ||
+ | |||
+ | enter dec *+4 | ||
+ | lda #$00 | ||
+ | sta store+3 | ||
+ | asl a | ||
+ | tax | ||
+ | lda #$00 | ||
+ | bcs next | ||
+ | |||
+ | ; sta table ;do whatever makes most sense for log(0) | ||
+ | rts</ |
base/8bit_logarithm_table_generator_routine.txt · Last modified: 2015-04-17 04:30 by 127.0.0.1