please dont rip this site

SX Microcontroller Math Method

BCD (packed) subtraction

From: Scott Dattalo

Translated and optimized for the Scenix SX by Nikolai Golovchenko

;******************************************
;bcd_sub
;
; Computes  x = x - y
; where x and y are all 8-bit packed BCD numbers
; Exits with C=0 if x<y, and with z=1 if x-y = 0
;
; Size: 14 instructions
; Execution time including return: 14/15 cycles

bcd_sub
	mov	W, y		;x = x - y
	sub	x, W

	clr	W
	sb	DC		;if lsn of x < lsn of y (dec)
	 or	W, #$06	;then substract extra 6
	snb	C		;Similarly for the msn
	 jmp	bcd_sub2

	or	W, #$60
	sub	x, W		;correct result
	clrb	C		;restore carry
	ret
bcd_sub2
	sub	x, W		;correct result
	setb	C		;restore carry
	ret

With result in a different register:

;******************************************
;bcd_sub_to
;
; Computes  s = x - y
; where x and y are all 8-bit packed BCD numbers
; Exits with C=0 if x<y, and with z=1 if x-y = 0
;
; Size: 15 instructions
; Execution time including return: 15/16 cycles

bcd_sub_to
	mov	W, y		;x = x - y
	mov	W, x-W
	mov	s, W

	clr	W
	sb	DC		;if lsn of x < lsn of y (dec)
	 or	W, #$06	;then substract extra 6
	snb	C		;Similarly for the msn
	 jmp	bcd_sub_to2

	or	W, #$60
	sub	s, W		;correct result
	clrb	C		;restore carry
	ret
bcd_sub_to2
	sub	s, W		;correct result
	setb	C		;restore carry
	ret

file: /Techref/scenix/lib/math/sub/bcdp2_sx.htm, 1KB, , updated: 2004/6/10 14:40, local time: 2024/7/19 21:18,
TOP NEW HELP FIND: 
35.172.230.21: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://piclist.com/techref/scenix/lib/math/sub/bcdp2_sx.htm"> SX Microcontroller Math Method BCD (packed) subtraction</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 massmind.org, 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 piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .