please dont rip this site

SX Microcontroller Math Method

Divide 24 bit int by 16 bit int to 24 bit int

by Nikolai Golovchenko

;Inputs:
;   Dividend - AARGB0:AARGB1:AARGB2 (0 - most significant!)
;   Divisor  - BARGB0:BARGB1
;Temporary:
;   Counter  - LOOPCOUNT
;   Remainder- REMB0:REMB1
;Output:
;   Quotient - AARGB0:AARGB1:AARGB2
;   Remainder- REMB0:REMB1
;
;       Size: 28
; Max timing: 4+24*(6+6+4+3+7)-2+3+3=632 cycles (with return)
; Min timing: 4+24*(6+6+6+7)-2+3+3=608 cycles (with return)
;

FXD2416U:
	clr	REMB0
	clr	REMB1
	mov	W, #24
	mov	LOOPCOUNT, W
LOOPU2416
	rl	AARGB2		;shift left divider to pass next bit to remainder
	rl	AARGB1		;and shift in next bit of result
	rl	AARGB0

	rl	REMB1		;shift carry into remainder
	rl	REMB0

	rl	LOOPCOUNT		;save carry in counter

	mov	W, BARGB1		;substract divisor from remainder
	sub	REMB1, W
	mov	W, BARGB0
	sb	C
	movsz	W, ++BARGB0
	mov	W, REMB0-w	;keep that byte in W untill we make sure about borrow

	snb	C		;if no borrow
	setb	LOOPCOUNT.0	;set bit 0 of counter (saved carry)

	snb	LOOPCOUNT.0	;if no borrow
	jmp	UOK46LL		;jump

	mov	W, BARGB1		;restore remainder if borrow
	add	REMB1, W
	mov	W, REMB0		;read high byte of remainder to W
        				;to not change it by next instruction
UOK46LL
	mov	REMB0, W		;store high byte of remainder
	clrb	C		;copy bit 0 to carry
	rr	LOOPCOUNT		;and restore counter
	decsz	LOOPCOUNT		;decrement counter
	jmp	LOOPU2416		;and repeat loop if not zero

	rl	AARGB2		;shift in last bit of result
	rl	AARGB1
	rl	AARGB0
	ret



file: /Techref/scenix/lib/math/div/24by16_sx.htm, 2KB, , updated: 2004/6/10 13:40, local time: 2024/11/15 15:30, owner: NG--944,
TOP NEW HELP FIND: 
3.15.25.44:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.ecomorder.com/techref/scenix/lib/math/div/24by16_sx.htm"> SX Math Divide 24 bits by 16</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to massmind.ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .