In SX Microcontrollers, SX/B Compiler and SX-Key Tool, peterverkaik wrote: According to [url=http://www.sxlist.com/techref/ubicom/lib/math/sub/bcdp2_sx.htm]http://www.sxlist.com/techref/ubicom/lib/math/sub/bcdp2_sx.htm[/url] the following should also work (I removed the carry restore instructions as they are not needed) [code] 'calculate x-y where x and y are packed bcd values 'use val = sub_bcd x,y FUNC sub_bcd asm mov W,__PARAM2 ;__PARAM1 = __PARAM1 - __PARAM2 sub __PARAM1,W clr W sb DC ;if lsn of __PARAM1 < lsn of __PARAM2 (dec) or W,#$06 ;then substract extra 6 sb C ;Similarly for the msn or W, #$60 sub __PARAM1,W ;correct result endasm RETURN __PARAM1 ENDFUNC [/code] Notice that this calculates the more general x-y rather than x-1 regards peter ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=312193#m312264 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)