please dont rip this site

SX Microcontroller Math Method

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

by Nikolai Golovchenko

;   Dividend - AARGB0:AARGB1:AARGB2 (0 - most significant!)
;   Divisor  - BARGB0:BARGB1
;   Counter  - LOOPCOUNT
;   Remainder- REMB0:REMB1
;   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)

	clr	REMB0
	clr	REMB1
	mov	W, #24
	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
	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

file: /Techref/scenix/lib/math/div/24by16_sx.htm, 2KB, , updated: 2004/6/10 14:40, local time: 2024/7/17 09:58, owner: NG--944,

 ©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=""> 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?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!