base:16bit_division_16-bit_result
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:16bit_division_16-bit_result [2015-04-17 04:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 16-bit Division ====== | ||
+ | |||
+ | To make the most common integer multiplication/ | ||
+ | |||
+ | < | ||
+ | divisor = $58 ;$59 used for hi-byte | ||
+ | dividend = $fb ;$fc used for hi-byte | ||
+ | remainder = $fd ;$fe used for hi-byte | ||
+ | result = dividend ;save memory by reusing divident to store the result | ||
+ | |||
+ | divide lda #0 ;preset remainder to 0 | ||
+ | sta remainder | ||
+ | sta remainder+1 | ||
+ | ldx #16 ;repeat for each bit: ... | ||
+ | |||
+ | divloop asl dividend ; | ||
+ | rol dividend+1 | ||
+ | rol remainder ; | ||
+ | rol remainder+1 | ||
+ | lda remainder | ||
+ | sec | ||
+ | sbc divisor ; | ||
+ | tay ;lb result -> Y, for we may need it later | ||
+ | lda remainder+1 | ||
+ | sbc divisor+1 | ||
+ | bcc skip ;if carry=0 then divisor didn't fit in yet | ||
+ | |||
+ | sta remainder+1 ; | ||
+ | sty remainder | ||
+ | inc result ;and INCrement result cause divisor fit in 1 times | ||
+ | |||
+ | skip dex | ||
+ | bne divloop | ||
+ | rts | ||
+ | </ | ||
+ | |||
+ | Variations of the above routine have been published in several C=64 mags. In terms of speed AND memory usage it should be the optimum. |
base/16bit_division_16-bit_result.txt · Last modified: 2015-04-17 04:30 by 127.0.0.1