Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: D Finnigan Newsgroups: comp.sys.apple2.programmer Subject: Re: Binary-to-Decimal Conversion Subroutine 27-Apr-80 Woz Date: Mon, 12 Jan 2015 18:39:23 +0000 (UTC) Organization: Mac GUI Lines: 40 Message-ID: References: <0b8c643e-175b-4c18-8582-3973d54049de@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 12 Jan 2015 18:39:23 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ac9e0e4d7dd3957fb97803ee6801bab8"; logging-data="8530"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SsbahHey86kzk9IbE0phZ" User-Agent: Mac GUI Usenet In-Reply-To: <0b8c643e-175b-4c18-8582-3973d54049de@googlegroups.com> Cancel-Lock: sha1:vcydiwN7LHzUHHCUtkhu5kaZADY= Xref: csiph.com comp.sys.apple2.programmer:1476 wssimms wrote: > Am Montag, 12. Januar 2015 13:03:06 UTC-5 schrieb D Finnigan: >> This routine came up in a discussion in comp.sys.apple2 in November. >> >> It was published on pages 52 and 53 of the the Winter 1980 edition of The >> Apple Orchard Magazine. Following is my summary of the article and the >> source listing. >> >> >> Binary-to-Decimal Shortcut >> (Small is Beautiful) >> >> by Steve Wozniak >> > > This seems like the most obvious way to do a binary to decimal conversion > on the 6502, but I like the Woz-optimization (Woztimization?) of doing a > ROL in the high byte of the result instead of another round of ADC/STA. > Furthermore, in this article, Woz goes on to say: The algorithm works as follows. The first bit shifted out of the binary argument carries a weight of 2 to the 15th. It is added to the result which is subsequently doubled 15 times (in decimal), restoring the proper weight component. Each bit is treated in this manner. The high-order result byte, DEC2, can be shifted left at step (3) instead of added to itself in decimal since it will not exceed 9 ($FFFF = 06 55 35). If this is done, DEC2 need not be initialized to zero, since the original contents will be shifted out during execution. This optimization is implemented in the following 6502 subroutine [listed in my initial article - DF]. -- ]DF$ Apple II Book: http://macgui.com/newa2guide/ Usenet: http://macgui.com/usenet/ <-- get posts by email! Apple II Web & Blog hosting: http://a2hq.com/