view lib/alib/div16x8.a @ 2772:0a3f4d8ea6d5

Found ENDC in wrong location in dwread.asm and dwwrite.asm. Corrected. Moved the native 6309 code in dwread.asm and dwwrite.asm into the H6309 labeled area and changed IFEQ H6309 to IFNE H6309. Also moved the 57600bps 6809 code to the default location. This change had been done in the old dwread.asm and dwwrite.asm files to make it easier to follow. Though these two files were overwritten from the HDBDOS project dwread.asm and dwwrite.asm files. So this conversion needed to be done again so it made the source easier to follow.
author drencor-xeen
date Wed, 23 Jan 2013 12:36:55 -0600
parents 7d70b7e1cb21
children aaba193af04f
line wrap: on
line source

****************************************
* 16 x 8 bit integer divide

* Result must be an 8 bit value

* ENTRY: A = divisor
*        X = dividend

* EXIT:  A = remainder
*        B = quotient
*        all other registers (except CC) preserved

 nam 16x8 bit Divide
 ttl Assembler Library Module


 psect DIV168,0,0,0,0,0

 vsect
negcount rmb 1
 endsect

* Signed Divide
SDIV168:
 clr negcount,u
 PSHS A,X
 tst ,s
 bpl testquo
 lda ,s
 coma
 inca
 sta ,s
 inc negcount,u
testquo
 tst 1,s
 bpl ok
 ldd 1,s
 comb
 coma
 addd #$0001
 std 1,s
 inc negcount,u
ok
 puls a,x
 bsr DIV168
 dec negcount,u
 bne goforit
 pshs a,x
 lda ,s
 coma
 inca
 sta ,s
 ldd 1,s
 coma
 comb 
 addd #$0001
 std 1,s 
 puls a,x
goforit
 rts


DIV168:
 LDB #8 bit counter
 PSHS A,B,X save count and divisor and value
 TFR X,D put dividend in D

div1
 ASLB shift dividend and quotient
 ROLA
 CMPA 0,S is trial subtraction successful?
 BCS div2
 SUBA 0,S yes, subtract and set bit
 INCB in quotient

div2
 DEC 1,S count down bits
 BNE div1 loop till done
 LEAS 2,S clean stack
 PULS X,PC return

 endsect