<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeffrey Nonken&#039;s Bare Metal Blog</title>
	<atom:link href="http://baremetalblog.nonken.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://baremetalblog.nonken.net</link>
	<description>A weblog about embedded systems development</description>
	<lastBuildDate>Sun, 16 May 2010 16:51:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PIC-16 Bitwise Long Divide</title>
		<link>http://baremetalblog.nonken.net/?p=43</link>
		<comments>http://baremetalblog.nonken.net/?p=43#comments</comments>
		<pubDate>Sun, 16 May 2010 06:49:14 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Stupid Programmer Tricks]]></category>
		<category><![CDATA[Coding Corner]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=43</guid>
		<description><![CDATA[PIC-16 bitwise long divide requires handling the carries manually, but the preprocessor lets you choose the resolution at compile-time without changing the code.]]></description>
			<content:encoded><![CDATA[<p>I promised I&#8217;d post my long divide function for the PIC. There was a resounding silence &#8212; no surprise considering most if not all the comments to date have been spam.</p>
<p>I just hope the next poor slob who needs an assembly language divide function for the PIC can find this page with a web search.</p>
<p>So&#8230; the function I wrote for the PSoC part is pretty universal. You should be able to port it to your favorite 8-bit part with minimum fuss. However, the PIC-16 and PIC-14 micros have a really funky hole in their operation set: they don&#8217;t do add with carry (or subtract with borrow). I have no objection to RISC architecture, though I&#8217;m not entirely convinced that it&#8217;s inherently better than CISC &#8212; I simply have no real opinion on the subject &#8212; but come on, guys. You&#8217;ve gotten carried away with this one.  Add with carry? Just how crazy are you trying to be? It&#8217;s not a CISC operation and it would have made multi-byte arithmetic considerably simpler. This is probably my single biggest complaint about the PIC micros.</p>
<p>So I&#8217;ve created a separate PIC port for this routine, and I&#8217;m posting it here separately, because it&#8217;s a pain in the neck to port the PSoC version.</p>
<p>The other thing I&#8217;ve done here is taken advantage of Microchip&#8217;s much more extensive (read: &#8220;not brain dead&#8221;) preprocessor and created a version of the code where you can choose (at compile-time) how many bytes the dividend and divisor occupy. This makes it simple to port to however many bits of resolution you need, as long as it can be expressed in multiples of 8.</p>
<p>Enjoy!</p>
<pre>;
; Copyright 2009 Jeffrey J. Nonken
; License: permission granted for unlimited use and unlimited derived use.
; If you use this, I'd appreciate it if you'd give me credit.
; Just leave these comments intact or mention me in your comments. I don't need
; money for this, but I'd appreciate credit where it's due.
; (Though if you want to send me money, I won't refuse it. <img src='http://baremetalblog.nonken.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
;
; Like what I did here? Feel free to offer me a job. http://jeffrey.nonken.net/
;
; Let me know if you have any improvements. PLEASE let me know if you find bugs.

;
; This is an unsigned integer divide function, x bits divided by y bits.
; Stuff your values into "dividend" and "divisor" and call the function (div24by16 in this sample).
; Note that "dividend" is stored as an x+1-byte value, the high byte is used internally for overflow.
; Any value you place here will get stomped on. Nothing is preserved. If you need the dividend or
; divisor later, make sure they're stored someplace else too.
; The remainder is computed as a side-effect of the divide but we do not attempt to preserve it.
; A few lines of extra code could be written to return the remainder in "divisor", but it will take
; some shifting around to justify the value properly. Use the inverse of "mask" on the result in
; "dividend" and the value calculated in "shift_count" to figure that one out. Don't forget to
; include the overflow bit.
;
; I originally created this algorithm in the 1980s to work on an 8086 processor.
; Later I ported it to the Cypress M8 processor for 24 over 16. (That code is in the Times Square Ball, by the way.)
; In order to avoid some tricky stuff on the PIC 16 series processor I ported it to "C", ran a test on a simulator,
; debugged it, then got the PICC C compiler to generate assembly code for 16-over-16 bit. I hand-optimized the result.
; After porting it back to 24-over-16 bits I decided I could use constants and macros to create something that
; could handle any number of bytes for the dividend and divisor -- between compiles, I mean, not run-time.
; (That could happen too but it would be much less efficient. I already did a couple compromises just for this.)
; This is what's left.
;
; So set your dividend and divisor size (in bytes) at the start of this, change the function name to something
; appropriate, and import it into your project. Just make sure the dividend has as many bytes as the divisor,
; or more, when you pick DIVIDEND_SIZE and DIVISOR_SIZE. No, that doesn't refer to the values you pass to
; the function -- if dividend is smaller than divisor at run-time you'll just get zero as a quotient.
;
; I wasn't using the PICC C compiler to write the code for the project because it's not well-enough integrated
; into MPLAB to do simulation or emulation. I used Microchip's C18 compiler set to an 18F4455 MCU for the
; test/debug cycle, then used PICC C to generate the assembly.
;
; It's not pretty, but it works.
;

        INCLUDE defaults.inc

; Set your word sizes here.
DIVIDEND_SIZE   equ     3               ; Dividend size in bytes. Also the quotient size.
DIVISOR_SIZE    equ     2               ; Divisor size in bytes.
; End of configurable equates.

 if (DIVIDEND_SIZE &lt; DIVISOR_SIZE)      ; One caveat: dividend can't be smaller than divisor.
        error   "DIVIDEND_SIZE must be greater than or equal to DIVISOR_SIZE!"
 endif
MASK_SIZE       equ     DIVIDEND_SIZE   ; Number of bytes in the mask the same as dividend.
DIVISOR_MSB     equ     DIVISOR_SIZE-1  ; MSB offset for the divisor.
DIVIDEND_MSB    equ     DIVIDEND_SIZE-1 ; MSB offset. Doesn't include the overflow byte.

        UDATA

        GLOBAL dividend,divisor,quotient
quotient:                               ; Outgoing quotient is in dividend. Doesn't have to be, but if not,
                                        ;  you'll have to pre-clear the quotient and shift it separately.
                                        ;  I don't think you'll save anything doing that.
dividend:       RES     DIVIDEND_SIZE+1 ; Incoming dividend, outgoing quotient.
                                        ;  We reserve an extra byte for overflow (1 bit).

divisor:        RES     DIVISOR_SIZE    ; Incoming divisor. This gets destroyed too. Just shifted, actually.
mask:           RES     DIVIDEND_SIZE   ; Mask used to separate quotient from remainder.
shift_count:    RES     1               ; Number of shifts required to complete the operation.
                                        ;  Also number of bits in the quotient mask.
mask_count:                             ; Counter used to generate the mask.
                                        ;  (Re-use carry, we don't use both at one time.)
carry:          RES     1               ; Holding register for the carry bit for multi-byte arithmetic.

        CODE

;
; This function tries to be efficient by shifting both values to the far left to minimize the number of repititions
; through the main loop. That comes at a cost, of course, but I expect that most of the value pairs I use will do
; better this way.
;
; Here's the original comment block, modified. Note that it was written for 24x16 divide.
;----------------------------------------------------------------------------------
; Divide a 24-bit number by a 16-bit number. Leaves the quotient in the dividend
; (numerator) and throws away the remainder.
;
; This works like a classic long division; it shifts the numerator and denominator
; to the top of their respective words (so they are the same apparent magnitude), counts
; the number of shifts and uses it to calculate the number of subtracts needed as
; well as generate the mask that eliminates the remainder.
;
; This can easily be extended or reduced to accomodate various word sizes. There
; should be no problem dividing a smaller word by a larger, but you will have
; to virtually extend the numerator with zeros. Since the initial shift factor will
; start out negative you will need to fiddle with that; you do not want to quit
; if you generate a carry, but instead test the sign of the result. (You still will
; want to jump to .zero_quotient if the shift factor is negative. Note that a shift
; factor of zero is valid.) [This version tests for zero, not carry, so that's
; no longer true. Lowest valid shift factor is 1. Don't try to use a smaller dividend
; that divisor unless you want to modify the code. I doubt it's worth the trouble.]
;
; If you are expecting small values in the numerator or denominator, you can
; check the high byte for 0 and do 8-bit shifts before doing the final 1-bit shifts.
; Since the 8-bit-shift loop starts with a cmp (or tst) and a jump, the cost is
; only about 13 cycles if it is not necessary. [Cypress cycles.]
;
; If you need to keep the remainder it gets a bit more complicated. The calculated
; count, and the final calculated mask, will tell you where the remainder is in
; the numerator: the remainder's LSb is just above the highest 1-bit in the mask.
; You may need to copy it out, mask and shift it before saving the quotient. You
; can also contrive to save the quotient into a different word rather than into
; the numerator, in which case you only need to shift the remainder back around.
; However, this will cost you more shifts during the calculation (you need to
; shift the numerator and the quotient separately).
;
; You can save yourself several bytes of RAM storage by calculating the final
; mask on-the-fly.
;----------------------------------------------------------------------------------
; Please note several things.
; 1) This is little-endian. Stuff/retrieve the LSB of the value in the lowest
;    address of the dividend/divisor/quotient.
; 2) This is entirely, completely, 100% unsigned. Want signed? Write your own,
;    or preserve the signs and convert to absolute values before the divide,
;    calculate the sign of the quotient and complement if required. If you need a
;    reminder: the quotient's sign will be the exclusive-or of the two inputs'
;    signs. The remainder, should you choose to keep it, is the same sign as the
;    dividend.
; 3) Make sure you set (or clear) ALL the input bytes (dividend and divisor)
;    before calling. That should be obvious, but it's worth the reminder.

        GLOBAL div24by16
div24by16:
; Check for boundary conditions and set up the divide.
        clrf    dividend+DIVIDEND_SIZE  ; Clear the extra byte.
; Look for divide by zero.
        movf    divisor,w               ; See if the divisor is zero. Start with the LSB.
i = 1
        while i &lt; DIVISOR_SIZE
        iorwf   divisor+i,w             ; OR in the rest of the bytes.
i = i + 1
        endw
        skipz                           ; Any 'on'-bits will show here.
        goto    divisor_not_zero        ; Situation normal, keep going.

; Oh noes! Divide by zero. Can't have that.
        movlw   0FFh                    ; Divide by zero? Get as close to infinity as we can.
i = 0
        while i &lt; DIVIDEND_SIZE
        movwf   dividend+i
i = i + 1
        endw
        return;

; Passed the first hurdle: we have a non-zero divisor.
divisor_not_zero:
;divide.c: 62: }
;divide.c: 63: shift_count = 1;
                                        ; Shift-count is the difference in the number of bits, plus 1.
        movlw   1 + ((DIVIDEND_SIZE-DIVISOR_SIZE) &lt;&lt; 3)
        movwf   shift_count
;divide.c: 64: while ((divisor &amp; 0x8000) == 0)
        goto    divisor_shift_start

; Start with zero. Is the dividend larger? Add 8 bits for every byte larger.
; So in a 24x16 divide we start with 8.
; Add 1 for every time we shift the divisor left.
; Subtract 1 for every time we shift the dividend left.
; Plus one so we can use decfsz for the loop test. (Otherwise we have to test for borrow.)
divisor_shift_loop:
;divide.c: 65: {
;divide.c: 66: ++shift_count;
        incf    shift_count,f           ; Count up every time we shift the divisor left.
;divide.c: 67: divisor &lt;&lt;= 1;
        clrc
i = 0
        while i &lt; DIVISOR_SIZE
        rlf     divisor+i,f             ; Shift all bytes left, starting with the LSB.
i = i + 1
        endw
divisor_shift_start:
        btfss   divisor+DIVISOR_MSB,7   ; Stop shifting once the high bit is non-zero.
        goto    divisor_shift_loop

;divide.c: 68: }
;divide.c: 71: while ((dividend &amp; 0x8000) == 0)
        goto    dividend_shift_start

; OK, now shift the dividend, but this time count backwards on the shift count.
dividend_shift_loop:
;divide.c: 72: {
;divide.c: 73: if (--shift_count == 0)
        decfsz  shift_count,f                   ; If it reaches zero that means the divisor is larger!
        goto    shift_not_zero                  ; If that happens, our quotient is guaranteed to be zero.
; Oops. The shift value reached zero, which means the dividend's value is smaller than the divisor's,
; which means the quotient is zero. If you want to return the remainder you'll have to stick in some
; extra code here.
        ;divide.c: 74: {
;divide.c: 75: dividend = 0;
i = 0
        while i &lt; DIVIDEND_SIZE
        clrf    dividend+i                      ; Quotient is zero. Just clear it out the easy way.
i = i + 1
        endw
        return                                  ; Render the output and return.
; Still some meat on this, so keep going.
shift_not_zero:
;divide.c: 77: }
;divide.c: 78: dividend &lt;&lt;= 1;
        clrc                                    ; Clear the carry so as not to contaminate the value.
i = 0
        while i &lt; DIVIDEND_SIZE
        rlf     dividend+i,f                    ; Shift all dividend bytes left starting with the LSB.
i = i + 1
        endw
                                                ; We'll never shift anything into dividend+DIVIDEND_SIZE in this loop.
dividend_shift_start:
        btfss   dividend+DIVIDEND_MSB,7         ; See if the high bit is set.
        goto    dividend_shift_loop             ; If not, repeat until it is.
;divide.c: 79: }
;divide.c: 80: {
;divide.c: 81: unsigned char mask_count = shift_count;

; Now that we have shift_count, we know how big the quotient is. Use that to generate a mask.
; If you want to save RAM you can generate the mask on-the-fly just before returning.
; Just make sure you copy off mask_count first, because we destroy shift_count.
        movf    shift_count,w
        movwf   mask_count                      ; shift_count is guaranteed to be at least 1.
;divide.c: 82: mask = 0;
i = 0
        while i &lt; MASK_SIZE
        clrf    mask+i                          ; Start by clearing out the mask.
i = i + 1
        endw
;divide.c: 88: while (mask_count)
mask_shift_loop:
;divide.c: 89: {
;divide.c: 90: mask = (mask &lt;&lt; 1) | 1;

; (Notice we don't clear the carry first. Don't need to.)
i = 0
        while i &lt; MASK_SIZE
        rlf     mask+i,f                        ; For every count, shift left by 1...
i = i + 1
        endw
        bsf     (mask),0                        ;  ... and set the low bit.
;divide.c: 91: --mask_count;
        decfsz  mask_count,f                    ; Count down and repeat ad nauseum.
        goto    mask_shift_loop
;divide.c: 92: }
;divide.c: 93: }
;divide.c: 94: do

; Hey, guess what? After all that we finally get to do some division! Hurrah!
looping:
;divide.c: 95: {
;divide.c: 96: if (divisor &lt;= dividend)
; Remember your grade-school long division. Line up the values on the left. Can you subtract?
; If not, shift the divisor right 1 digit and try again. Of course, that's in base 10, so you need to
; find a multiplier to put up top. Easier for us here, it's just zero or 1. Once you do that
; multiply the divisor by the multiplier and subtract the result from the dividend.
; Move to the next column and repeat until you run out of dividend.
; Whatever is left is the remainder.
; So: Find out if we can subtract. If we can, do it and stick a 1 in the quotient, then shift the dividend left.
; If not, just shift the dividend left. Note that if we do that, we might end up with an extra bit off the high end.
; That's why we reserved an extra byte for the dividend.
        movf    (dividend+DIVIDEND_SIZE),w      ; First, see if the overflow bit is set.
        skipz
        goto    dividend_is_bigger              ; If dividend overflow byte is non-zero, dividend is bigger by definition.
                                                              ; Otherwise drop through to compare the two values.
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Can't really make a local label in a while/endw (assembler limitation) so we're making a macro to call.
        sub_byte        macro
        local next
        movf    (divisor+j),w
        subwf   (dividend+i),w
        skipnz
        goto    next                            ; If they're the same, drop through.
                                                ;  Either try the next one or if this is the last, allow the subtraction.
        skipnb                                  ; They're not the same, see which one is bigger.
        goto    divisor_is_bigger
 if j &gt; 0                                       ; If this is the last byte, just drop through.
        goto    dividend_is_bigger
 endif
next:
        endm
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

; Start from the highest byte and compare. It's just a gt/lt/eq comparison so we don't need borrows and so on.
; As soon as we see one is larger than the other we can stop. If they're equal it's OK to do the subtract,
; so we treat that the same as the dividend being larger.
i = DIVIDEND_MSB
j = DIVISOR_MSB                                 ; Start with the most significant byte of each value.
        while j &gt;= 0                            ; Keep trying until we run out of divisor.
        sub_byte                                ; Run the macro (above). Any difference jumps out of the while/endw "loop".
j = j - 1
i = i - 1                                       ; Still the same, try the next byte.
        endw
; Both values being the same is OK too. Drop through to dividend_is_bigger.

; If we get here, either the dividend is bigger or they're exactly the same. Either way we can do the subtraction.
dividend_is_bigger:
;divide.c: 97: {
;divide.c: 98: dividend = ((dividend - divisor) &lt;&lt; 1) | 1;
j = 0                                           ; Start the divisor index at zero.
i = DIVIDEND_MSB - DIVISOR_MSB                  ; Count backwards from the dividend MSB so we do the same number of bytes.
        while j &lt; DIVISOR_SIZE ; First, take care of the borrow from the previous byte.
 if j &gt; 0                                       ; No borrow waiting on the first byte!
        movf    carry,w                         ; Get the borrow from the previous byte.
        subwf   dividend+i,f                    ; Subtract it from the current byte.
        clrf    carry                           ; Clear the borrow...
        skipnb
        incf    carry,f                         ;  ...and set it again if we have a new one.
 else
        clrf    carry                           ; First byte, just clear the borrow.
 endif
 ; Now do the subtract.
        movf    divisor+j,w                     ; Get the divisor,
        subwf   dividend+i,f                    ; subtract from the dividend.
        skipnb
        incf    carry,f                         ; Add to the borrow.
                                                ; The borrow, "carry", will be 0 or 1 here, carried forward to the next byte.
j = j + 1
i = i + 1                                       ; Move on to the next byte.
        endw
        movf    carry,w
        subwf   (dividend+DIVIDEND_SIZE),f      ; Extend the borrow to the overflow byte.
i = 0
        while i &lt;= DIVIDEND_SIZE
        rlf     dividend+i,f                    ; Now shift the dividend left for the next subtract.
i = i + 1
        endw
        bsf     (dividend+0),0                  ; This subtract succeeded, so record a "1" bit in the quotient.
;divide.c: 99: }
        goto    loop_continue

; If we get here the subtract failed; just shift the dividend left and record a "0" bit in the quotient.
; This is where the dividend overflow byte comes into play. We wouldn't need it otherwise.
divisor_is_bigger:
;divide.c: 100: else
;divide.c: 101: {
;divide.c: 102: dividend = (dividend &lt;&lt; 1);
        clrc                                    ; Clear the carry ahead of time (that "0" we mentioned above).
i = 0
        while i &lt;= DIVIDEND_SIZE                ; (Note this says "less-than-or-equal" to accomodate the overflow.)
        rlf     dividend+i,f                    ; Shift all the bytes left, including the overflow.
i = i + 1
        endw

; Decide whether we're finished the divide, and loop if not.
loop_continue:
;divide.c: 103: }
;divide.c: 104: } while (--shift_count);
        decfsz  shift_count,f                   ; Count down, skip if finished.
        goto    looping                         ; Not finished, start another iteration.

; Hey, we're finally finished! Strip away the remainder and return.
; The mask can be generated on-the-fly here if desired to save RAM, though it might cost cycles.
; Then again, maybe not.
; If you want to return the remainder, now's the time.
;divide.c: 105: dividend &amp;= mask;
i = 0
        while i &lt; DIVIDEND_SIZE
        movf    mask+i,w
        andwf   dividend+i,f                    ; Strip away the remainder, leaving only the quotient.
i = i + 1
        endw
;       clrf    dividend + DIVIDEND_SIZE        ; Clear the overflow byte. Probably redundant.
;divide.c: 106: }
        return

        end</pre>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=43</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Too much spam</title>
		<link>http://baremetalblog.nonken.net/?p=40</link>
		<comments>http://baremetalblog.nonken.net/?p=40#comments</comments>
		<pubDate>Mon, 19 Apr 2010 14:26:10 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Meta-blogging]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=40</guid>
		<description><![CDATA[I&#8217;m sorry to have to do this so early in the game, but the spam is already somewhere between &#8220;annoying&#8221; and &#8220;overwhelming&#8221;. I&#8217;m going to start requiring registration to post comments.
Many thanks to those real humans who have taking the time to read and especially comment on my blog.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sorry to have to do this so early in the game, but the spam is already somewhere between &#8220;annoying&#8221; and &#8220;overwhelming&#8221;. I&#8217;m going to start requiring registration to post comments.</p>
<p>Many thanks to those <em>real humans</em> who have taking the time to read and especially comment on my blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=40</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PSoC M8 Bitwise Long Divide</title>
		<link>http://baremetalblog.nonken.net/?p=34</link>
		<comments>http://baremetalblog.nonken.net/?p=34#comments</comments>
		<pubDate>Sat, 06 Mar 2010 16:44:04 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Stupid Programmer Tricks]]></category>
		<category><![CDATA[Coding Corner]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=34</guid>
		<description><![CDATA[Jeff gives you some bitwise long-division code for an 8-bit microprocessor.]]></description>
			<content:encoded><![CDATA[<p>One problem with 8-bit micros is that their math processing is usually limited to addition and subtraction. You can do a lot with addition and subtraction, but sometimes you need to do multiplication and division. Even the mighty 8086 didn&#8217;t get its FPU built in until the 80386 (and it was optional until the Pentium, if I remember correctly) though you could get an external FPU.</p>
<p>Of the two processors I use most (the Microchip PIC18 and the Cypress M8) each has an 8-bit multiply function accessible via registers (though the M8 is a signed multiply &#8212; who was the genius who thought that up? It makes a mess of doing multi-word multiplies). And multiply is comparatively simple to write.</p>
<p>But to do a proper divide requires more work. Especially if you don&#8217;t want to just subtract the divisor from the dividend and add 1 to the quotient until you run out of dividend. It works, but it&#8217;s terribly slow.</p>
<p>I&#8217;m not very strong on math so I fell back on what I knew. What I knew was long division as taught to me in elementary school. You know &#8212; subtract a multiple of the divisor from the top of the dividend, record the multiplier, calculate the remainder, then do it again on the remainder. Wash, rinse, repeat until you run out of dividend or patience. (OK, not the best description, but you already know the drill.)</p>
<p>So that&#8217;s what I did for my bitwise long divide. I first wrote it for the 8086, later I ported it to the M8, then the PIC16, then the M8 again when I lost the first code. I&#8217;ve ported it to several different sizes of dividend and divisor; with some work I could probably make it run-time adaptable but of course that would only slow it down. I did make a macro version for the PIC16 that uses preprocessor directives (while/endw mostly) to let you generate code for any size words you like. I don&#8217;t think I can do that for the M8, their preprocessor is very primitive. The original M8 code is in the Times Square Ball firmware, by the way. What I&#8217;ll be giving you has been ported twice since then, but it&#8217;s essentially the same. (I&#8217;ll give you the PIC16 code in a separate blog post, fear not.)</p>
<p>Here&#8217;s the general idea. First, shift both values (dividend and divisor) left until each is at the top of its word. Keep track of how many times you shifted each (plus the difference in word size); that tells you how many bits will be in your quotient (and indirectly your remainder), though it doesn&#8217;t say how many of those bits are set to 1, don&#8217;t get me wrong. But the quotient will never be any larger than that number of bits. That number also tells you when to stop subtracting; it&#8217;s a counter.</p>
<p>Next you do a subtract-test-record-shift cycle exactly like the one in your by-hand long division, except that ours is in binary. You are shifting the dividend, not the divisor (which stays constant).</p>
<p>Now here&#8217;s the tricky bit. Every time you do a subtract-shift you discard one bit of significance. That means that a new low bit becomes available in the dividend on each cycle. So instead of putting that bit into a separate quotient (and requiring a second set of shifts &#8212; remember that we&#8217;re in a slow, 8-bit processor), you can set the result of your subtract into the low bit of the dividend <em>after</em> you&#8217;ve shifted it. Of course that means you can&#8217;t (easily) test for zero to see if you&#8217;re through; that&#8217;s why you need that counter. Still, leaving the divide early due to the dividend going to zero is an unusual case, I should think. (And if it is not, in your particular case, due to peculiarities of your particular data set, then you obviously want to optimize your code to take advantage of that.)</p>
<p>That leaves the quotient in the dividend. But what about the leftover bits after the last subtract? Well&#8230; that&#8217;s your remainder.</p>
<p>Now early on we determined how many bits the quotient would have. We use this to generate a mask that lets us preserve the quotient and throw away the remainder. But what if you need the remainder? That&#8217;s a bit more work but it turns out to be exactly the number of bits remaining that aren&#8217;t quotient. All you have to do is copy, mask, and shift right by &#8212; guess what? &#8212; the number of bits in the quotient, the same counter we calculated up front. (Actually you can skip the &#8216;mask&#8217; step for the remainder since you&#8217;re going to shift the quotient into the bit bucket anyway.)</p>
<p>Cool stuff, Maynard.</p>
<p>Unfortunately I haven&#8217;t figured out how to attach files to this blog (except media). I can of course upload elsewhere and link to it. Meantime I&#8217;m going to try to simply paste it into the blog.</p>
<p>Bonus! Here I am giving you two different word sizes, 24/16 and 32/16. The differences should be obvious; it should help if you ever need to port to other word sizes. Please note however that the design doesn&#8217;t really allow for the divisor to have more bits than the dividend.</p>
<p>One other note in reference to my post &#8220;Optimize This!&#8221; regarding re-use of variables. Note that I do that here. First, it&#8217;s stable, test code; second, you&#8217;ll notice that I gave the variable two different, meaningful labels for the two separate uses; third, you&#8217;ll notice that I commented it.</p>
<p>On the other hand, I didn&#8217;t really comment the code as much as I usually do. I did however leave in the C code (as comments) I used during one porting process.</p>
<p>One last note: notwithstanding the number of bits we counted, when you store the results the quotient word size is the same as the dividend and the remainder is the same word size as the divisor. Again, that&#8217;s the general case and your dataset may generate smaller words, optimize for your dataset.</p>
<pre>;
; Copyright 2010 Jeffrey J. Nonken
; License: permission granted for unlimited use and unlimited derived use.
; If you use this, I'd appreciate it if you'd give me credit.
; Just leave these comments intact or mention me in your comments. I don't need
; money for this, but I'd appreciate credit where it's due.
; (Though if you want to send me money, I won't refuse it. <img src='http://baremetalblog.nonken.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
;
; Like what I did here? Feel free to offer me a job. http://jeffrey.nonken.net/
;
; Let me know if you have any improvements. PLEASE let me know if you find bugs.

;
; This is an integer divide function, 24 bits divided by 16 bits.
; Stuff your 24-bit value into "dividend", 16-bit value into "divisor" and call div24by16.
; Note that "dividend" is a 4-byte value, the high byte is used internally for overflow.
; Any value you place there will get squashed first thing.
; The quotient of the divide will be left in dividend, so make sure your value is safe someplace else.
; For that matter, I destroy divisor, too.
; The remainder is computed as a side-effect of the divide but we do not attempt to preserve it.
; A few lines of extra code could be written to return the remainder in "divisor", but it will take
; some shifting around to justify the value properly. Use the inverse of "mask" on the result in
; "divisor" and the value calculated in "shift_count" to figure that one out. Don't forget to
; include the overflow bit.
;
; I originally created this algorithm in the 1980s to work on an 8086 processor.
; Later I ported it to the Cypress M8 processor for 24 over 16. [That code is in the Times Square Ball, by the way.]
; In order to avoid some tricky stuff on the PIC 16 series processor I ported it to "C", ran a test on a simulator,
; debugged it, then got the PICC C compiler to generate assembly code. I hand-optimized the result.
; This is what's left.
;
; I wasn't using the PICC C compiler to write the code for the project because it's not well-enough integrated
; into MPLAB to do simulation or emulation. I used Microchip's C18 compiler set to an 18F4455 MCU for the
; test/debug cycle, then used PICC C to generate the assembly.
;
; It's not pretty, but it works.
;

    AREA	bss [RAM, REL]

quotient::					; Outgoing quotient is in dividend.
dividend::		BLK	5		; Incoming dividend, outgoing quotient.
divisor::		BLK	2		; Incoming divisor. This gets destroyed.
mask:			BLK	4		; Mask used to separate quotient from remainder.
shift_count:		BLK	1		; Number of shifts required to complete the operation.
                                                ;  Also number of bits in the quotient mask.
mask_count:					; Counter used to generate the mask.
                                                ;  [Re-use carry, we don't use both at one time.]
carry:			BLK	1		; Holding register for the carry bit. Used in the only
                                                ;  true 3-byte operation we have.

    AREA text [ROM, REL, CON]

;
; This function tries to be efficient by shifting both values to the far left to minimize the number of repititions
; through the main loop. That comes at a cost, of course, but I expect that most of the value pairs I use will do
; better this way.
;
; Dividing 1024 by 33 takes about 345 cycles, including the call/return. Just for the record.
;
; Here's the original comment block. Note that it was written for 24x16 divide.
;----------------------------------------------------------------------------------
; Divide a 24-bit number by a 16-bit number. Leaves the quotient in the dividend
; [numerator] and throws away the remainder.
;
; This works like a classic long division; it shifts the numerator and denominator
; to the top of their respective words [so they are the same magnitude], counts
; the number of shifts and uses it to calculate the number of subtracts needed as
; well as the mask that eliminates the remainder.
;
; This can easily be extended or reduced to accomodate various word sizes. There
; should be no problem dividing a smaller word by a larger, but you will have
; to virtually extend the numerator with zeros. Since the initial shift factor will
; start out negative you will need to fiddle with that; you do not want to quit
; if you generate a carry, but instead test the sign of the result. [You still will
; want to jump to .zero_quotient if the shift factor is negative. Note that a shift
; factor of zero is valid.] [This version tests for zero, not carry, so that's
; no longer true. Lowest valid shift factor is 1.]
;
; If you expect to be using long words or want to macro-ize this [or expect to
; adapt it a lot] you may want to use multi-byte words and index into them
; [e.g. [numerator+1] instead of discrete names for each byte. However, the result
; will be endian-dependent. [This one is little-endian.]
;
; If you are expecting small values in the numerator or denominator, you can
; check the high byte for 0 and do 8-bit shifts before doing the final 1-bit shifts.
; Since the 8-bit-shift loop starts with a cmp [or tst] and a jump, the cost is
; only about 13 cycles if it is not necessary. [Cypress cycles.]
;
; If you need to keep the remainder it gets a bit more complicated. The calculated
; count, and the final calculated mask, will tell you where the remainder is in
; the numerator: the remainder's LSb is just above the highest 1-bit in the mask.
; You may need to copy it out, mask and shift it before saving the quotient. You
; can also contrive to save the quotient into a different word rather than into
; the numerator, in which case you only need to shift the remainder back around.
; However, this will cost you more shifts during the calculation [you need to
; shift the numerator and the quotient separately].
;
; You can save yourself several bytes of RAM storage by calculating the final
; mask on-the-fly.
;----------------------------------------------------------------------------------

div24by16::
; Check for boundary conditions and set up the divide.
    mov		[dividend+3],0
; Look for divide by zero.
    mov		a,[divisor+1]		; See if the divisor is zero.
    or		a,[divisor]
    jnz		.divisor_not_zero
; Divide by zero.
    mov		a,0xFF			; Divide by zero? Get as close to infinity as we can.
    mov		[dividend],a
    mov		[dividend+1],a
    mov		[dividend+2],a
    ret

.divisor_not_zero:
;divide.c: 62: }
;divide.c: 63: shift_count = 1;
    mov		[shift_count],1+8			; Difference in #bits between dividend and divisor. Plus 1.
;divide.c: 64: while [[divisor &amp; 0x8000] == 0]
    jmp		.divisor_shift_start

.divisor_shift_loop:
;divide.c: 65: {
;divide.c: 66: ++shift_count;
    inc		[shift_count]
;divide.c: 67: divisor &lt;&lt;= 1;
    asl		[divisor]
    rlc		[divisor+1]
.divisor_shift_start:
    tst		[divisor+1],0b10000000
    jz		.divisor_shift_loop
    jmp		.dividend_shift_start

.dividend_shift_loop:
;divide.c: 72: {
;divide.c: 73: if [--shift_count == 0]
    dec		[shift_count]
    jnz		.l10
;divide.c: 74: {
;divide.c: 75: dividend = 0;
    mov		[dividend],0
    mov		[dividend+1],0
    mov		[dividend+2],0
                ; dividend+3 is already zero.
    ret			; Render the output and return.

.l10:
;divide.c: 77: }
;divide.c: 78: dividend &lt;&lt;= 1;
    asl		[dividend]
    rlc		[dividend+1]
    rlc		[dividend+2]
                                        ; We'll never shift anything into dividend+3 in this loop.
.begin_continue:
.dividend_shift_start:
    tst		[dividend+2],0b10000000		; See if the high bit is set.
    jz		.dividend_shift_loop		; If not, repeat until it is.
;divide.c: 79: }
;divide.c: 80: {
;divide.c: 81: unsigned char mask_count = shift_count;
    mov		[mask_count],[shift_count]	; shift_count is guaranteed to be at least 1.
;divide.c: 82: mask = 0;
    mov		[mask],0
    mov		[mask+1],0
    mov		[mask+2],0
;divide.c: 88: while [mask_count]
.mask_shift_loop:
;divide.c: 89: {
;divide.c: 90: mask = [mask &lt;&lt; 1] | 1;
    asl		[mask]
    rlc		[mask+1]
    rlc		[mask+2]
    or		[mask],1
;divide.c: 91: --mask_count;
    dec		[mask_count]
    jnz		.mask_shift_loop
;divide.c: 92: }
;divide.c: 93: }
;divide.c: 94: do

.looping:
;divide.c: 95: {
;divide.c: 96: if [divisor &lt;= dividend]
    mov		a,[dividend+3]			; Dividend has a higher byte than divisor.
    jnz		.dividend_is_bigger		; If dividend high byte is non-zero, dividend is bigger by definition.
    mov		a,[divisor+1]
    sub		a,[dividend+2]
    jnz		.u925
    mov		a,[divisor]
    sub		a,[dividend+1]
    jz		.dividend_is_bigger
.u925:
    jnc		.divisor_is_bigger		; They're not the same, see which one is bigger.
.dividend_is_bigger:
;divide.c: 97: {
;divide.c: 98: dividend = [[dividend - divisor] &lt;&lt; 1] | 1;
    mov		a,[divisor]
    sub		[dividend+1],a
    mov		a,[divisor+1]
    sbb		[dividend+2],a
    sbb		[dividend+3],0
    asl		[dividend+0]
    rlc		[dividend+1]
    rlc		[dividend+2]
    rlc		[dividend+3]
    or		[dividend+0],1
;divide.c: 99: }
    jmp		.l19

.divisor_is_bigger:
;divide.c: 100: else
;divide.c: 101: {
;divide.c: 102: dividend = [dividend &lt;&lt; 1];
    asl		[dividend+0]
    rlc		[dividend+1]
    rlc		[dividend+2]
    rlc		[dividend+3]

.l19:
;divide.c: 103: }
;divide.c: 104: } while [--shift_count];
    dec		[shift_count]
    jnz		.looping
.u950:

.l16:
;divide.c: 105: dividend &amp;= mask;
    mov		a,[mask]
    and		[dividend],a
    mov		a,[mask+1]
    and		[dividend+1],a
    mov		a,[mask+2]
    and		[dividend+2],a
    mov		[dividend+3],0
;divide.c: 106: }
    ret

;----------------------------------------------------------------------------------
; Divide a 32-bit number by a 16-bit number. Leaves the quotient in the dividend
; [numerator] and throws away the remainder.
;
; This works like a classic long division; it shifts the numerator and denominator
; to the top of their respective words [so they are the same magnitude], counts
; the number of shifts and uses it to calculate the number of subtracts needed as
; well as the mask that eliminates the remainder.
;
; This can easily be extended or reduced to accomodate various word sizes. There
; should be no problem dividing a smaller word by a larger, but you will have
; to virtually extend the numerator with zeros. Since the initial shift factor will
; start out negative you will need to fiddle with that; you do not want to quit
; if you generate a carry, but instead test the sign of the result. [You still will
; want to jump to .zero_quotient if the shift factor is negative. Note that a shift
; factor of zero is valid.] [This version tests for zero, not carry, so that's
; no longer true. Lowest valid shift factor is 1.]
;
; If you expect to be using long words or want to macro-ize this [or expect to
; adapt it a lot] you may want to use multi-byte words and index into them
; [e.g. [numerator+1] instead of discrete names for each byte. However, the result
; will be endian-dependent. [This one is little-endian.]
;
; If you are expecting small values in the numerator or denominator, you can
; check the high byte for 0 and do 8-bit shifts before doing the final 1-bit shifts.
; Since the 8-bit-shift loop starts with a cmp [or tst] and a jump, the cost is
; only about 13 cycles if it is not necessary. [Cypress cycles.]
;
; If you need to keep the remainder it gets a bit more complicated. The calculated
; count, and the final calculated mask, will tell you where the remainder is in
; the numerator: the remainder's LSb is just above the highest 1-bit in the mask.
; You may need to copy it out, mask and shift it before saving the quotient. You
; can also contrive to save the quotient into a different word rather than into
; the numerator, in which case you only need to shift the remainder back around.
; However, this will cost you more shifts during the calculation [you need to
; shift the numerator and the quotient separately].
;
; You can save yourself several bytes of RAM storage by calculating the final
; mask on-the-fly.
;----------------------------------------------------------------------------------

div32by16::
; Check for boundary conditions and set up the divide.
    mov		[dividend+4],0
; Look for divide by zero.
    mov		a,[divisor+1]		; See if the divisor is zero.
    or		a,[divisor]
    jnz		.divisor_not_zero
; Divide by zero.
    mov		a,0xFF			; Divide by zero? Get as close to infinity as we can.
    mov		[dividend],a
    mov		[dividend+1],a
    mov		[dividend+2],a
    mov		[dividend+3],a
    ret

.divisor_not_zero:
;divide.c: 62: }
;divide.c: 63: shift_count = 1;
    mov		[shift_count],1+16			; Difference in #bits between dividend and divisor. Plus 1.
;divide.c: 64: while [[divisor &amp; 0x8000] == 0]
    jmp		.divisor_shift_start

.divisor_shift_loop:
;divide.c: 65: {
;divide.c: 66: ++shift_count;
    inc		[shift_count]
;divide.c: 67: divisor &lt;&lt;= 1;
    asl		[divisor]
    rlc		[divisor+1]
.divisor_shift_start:
    tst		[divisor+1],0b10000000
    jz		.divisor_shift_loop
    jmp		.dividend_shift_start

.dividend_shift_loop:
;divide.c: 72: {
;divide.c: 73: if [--shift_count == 0]
    dec		[shift_count]
    jnz		.l10
;divide.c: 74: {
;divide.c: 75: dividend = 0;
    mov		[dividend],0
    mov		[dividend+1],0
    mov		[dividend+2],0
    mov		[dividend+3],0
                ; dividend+4 is already zero.
    ret			; Render the output and return.

.l10:
;divide.c: 77: }
;divide.c: 78: dividend &lt;&lt;= 1;
    asl		[dividend]
    rlc		[dividend+1]
    rlc		[dividend+2]
    rlc		[dividend+3]
                                        ; We'll never shift anything into dividend+4 in this loop.
.begin_continue:
.dividend_shift_start:
    tst		[dividend+3],0b10000000		; See if the high bit is set.
    jz		.dividend_shift_loop		; If not, repeat until it is.
;divide.c: 79: }
;divide.c: 80: {
;divide.c: 81: unsigned char mask_count = shift_count;
    mov		[mask_count],[shift_count]	; shift_count is guaranteed to be at least 1.
;divide.c: 82: mask = 0;
    mov		[mask],0
    mov		[mask+1],0
    mov		[mask+2],0
    mov		[mask+3],0
;divide.c: 88: while [mask_count]
.mask_shift_loop:
;divide.c: 89: {
;divide.c: 90: mask = [mask &lt;&lt; 1] | 1;
    asl		[mask]
    rlc		[mask+1]
    rlc		[mask+2]
    rlc		[mask+3]
    or		[mask],1
;divide.c: 91: --mask_count;
    dec		[mask_count]
    jnz		.mask_shift_loop
;divide.c: 92: }
;divide.c: 93: }
;divide.c: 94: do

.looping:
;divide.c: 95: {
;divide.c: 96: if [divisor &lt;= dividend]
    mov		a,[dividend+4]			; Dividend has a higher byte than divisor.
    jnz		.dividend_is_bigger		; If dividend high byte is non-zero, dividend is bigger by definition.
    mov		a,[divisor+1]
    sub		a,[dividend+3]
    jnz		.u925
    mov		a,[divisor]
    sub		a,[dividend+2]
    jz		.dividend_is_bigger
.u925:
    jnc		.divisor_is_bigger		; They're not the same, see which one is bigger.
.dividend_is_bigger:
;divide.c: 97: {
;divide.c: 98: dividend = [[dividend - divisor] &lt;&lt; 1] | 1;
    mov		a,[divisor]
    sub		[dividend+2],a
    mov		a,[divisor+1]
    sbb		[dividend+3],a
    sbb		[dividend+4],0
    asl		[dividend+0]
    rlc		[dividend+1]
    rlc		[dividend+2]
    rlc		[dividend+3]
    rlc		[dividend+4]
    or		[dividend+0],1
;divide.c: 99: }
    jmp		.l19

.divisor_is_bigger:
;divide.c: 100: else
;divide.c: 101: {
;divide.c: 102: dividend = [dividend &lt;&lt; 1];
    asl		[dividend+0]
    rlc		[dividend+1]
    rlc		[dividend+2]
    rlc		[dividend+3]
    rlc		[dividend+4]

.l19:
;divide.c: 103: }
;divide.c: 104: } while [--shift_count];
    dec		[shift_count]
    jnz		.looping
.u950:

.l16:
;divide.c: 105: dividend &amp;= mask;
    mov		a,[mask]
    and		[dividend],a
    mov		a,[mask+1]
    and		[dividend+1],a
    mov		a,[mask+2]
    and		[dividend+2],a
    mov		a,[mask+3]
    and		[dividend+3],a
    mov		[dividend+4],0
;divide.c: 106: }
    ret</pre>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 673px; width: 1px; height: 1px;">;<br />
; Copyright 2010 Jeffrey J. Nonken<br />
; License: permission granted for unlimited use and unlimited derived use.<br />
; If you use this, I&#8217;d appreciate it if you&#8217;d give me credit.<br />
; Just leave these comments intact or mention me in your comments. I don&#8217;t need<br />
; money for this, but I&#8217;d appreciate credit where it&#8217;s due.<br />
; (Though if you want to send me money, I won&#8217;t refuse it. <img src='http://baremetalblog.nonken.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
;<br />
; Like what I did here? Feel free to offer me a job. http://jeffrey.nonken.net/<br />
;<br />
; Let me know if you have any improvements. PLEASE let me know if you find bugs.</p>
<p>;<br />
; This is an integer divide function, 24 bits divided by 16 bits.<br />
; Stuff your 24-bit value into &#8220;dividend&#8221;, 16-bit value into &#8220;divisor&#8221; and call div24by16.<br />
; Note that &#8220;dividend&#8221; is a 4-byte value, the high byte is used internally for overflow.<br />
; Any value you place there will get squashed first thing.<br />
; The quotient of the divide will be left in dividend, so make sure your value is safe someplace else.<br />
; For that matter, I destroy divisor, too.<br />
; The remainder is computed as a side-effect of the divide but we do not attempt to preserve it.<br />
; A few lines of extra code could be written to return the remainder in &#8220;divisor&#8221;, but it will take<br />
; some shifting around to justify the value properly. Use the inverse of &#8220;mask&#8221; on the result in<br />
; &#8220;divisor&#8221; and the value calculated in &#8220;shift_count&#8221; to figure that one out. Don&#8217;t forget to<br />
; include the overflow bit.<br />
;<br />
; I originally created this algorithm in the 1980s to work on an 8086 processor.<br />
; Later I ported it to the Cypress M8 processor for 24 over 16. [That code is in the Times Square Ball, by the way.]<br />
; In order to avoid some tricky stuff on the PIC 16 series processor I ported it to &#8220;C&#8221;, ran a test on a simulator,<br />
; debugged it, then got the PICC C compiler to generate assembly code. I hand-optimized the result.<br />
; This is what&#8217;s left.<br />
;<br />
; I wasn&#8217;t using the PICC C compiler to write the code for the project because it&#8217;s not well-enough integrated<br />
; into MPLAB to do simulation or emulation. I used Microchip&#8217;s C18 compiler set to an 18F4455 MCU for the<br />
; test/debug cycle, then used PICC C to generate the assembly.<br />
;<br />
; It&#8217;s not pretty, but it works.<br />
;</p>
<p>AREA    bss [RAM, REL]<br />
AREA InterruptRAM      [RAM, REL, CON]   ; Interrupts, on Page 0</p>
<p>quotient::                    ; Outgoing quotient is in dividend.<br />
dividend::        BLK    5        ; Incoming dividend, outgoing quotient.<br />
divisor::        BLK    2        ; Incoming divisor. This gets destroyed.<br />
mask:            BLK    4        ; Mask used to separate quotient from remainder.<br />
shift_count:    BLK    1        ; Number of shifts required to complete the operation.<br />
;  Also number of bits in the quotient mask.<br />
mask_count:                    ; Counter used to generate the mask.<br />
;  [Re-use carry, we don't use both at one time.]<br />
carry:            BLK    1        ; Holding register for the carry bit. Used in the only<br />
;  true 3-byte operation we have.</p>
<p>AREA text [ROM, REL, CON]</p>
<p>;<br />
; This function tries to be efficient by shifting both values to the far left to minimize the number of repititions<br />
; through the main loop. That comes at a cost, of course, but I expect that most of the value pairs I use will do<br />
; better this way.<br />
;<br />
; Dividing 1024 by 33 takes about 345 cycles, including the call/return. Just for the record.<br />
;<br />
; Here&#8217;s the original comment block. Note that it was written for 24&#215;16 divide.<br />
;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
; Divide a 24-bit number by a 16-bit number. Leaves the quotient in the dividend<br />
; [numerator] and throws away the remainder.<br />
;<br />
; This works like a classic long division; it shifts the numerator and denominator<br />
; to the top of their respective words [so they are the same magnitude], counts<br />
; the number of shifts and uses it to calculate the number of subtracts needed as<br />
; well as the mask that eliminates the remainder.<br />
;<br />
; This can easily be extended or reduced to accomodate various word sizes. There<br />
; should be no problem dividing a smaller word by a larger, but you will have<br />
; to virtually extend the numerator with zeros. Since the initial shift factor will<br />
; start out negative you will need to fiddle with that; you do not want to quit<br />
; if you generate a carry, but instead test the sign of the result. [You still will<br />
; want to jump to .zero_quotient if the shift factor is negative. Note that a shift<br />
; factor of zero is valid.] [This version tests for zero, not carry, so that's<br />
; no longer true. Lowest valid shift factor is 1.]<br />
;<br />
; If you expect to be using long words or want to macro-ize this [or expect to<br />
; adapt it a lot] you may want to use multi-byte words and index into them<br />
; [e.g. [numerator+1] instead of discrete names for each byte. However, the result<br />
; will be endian-dependent. [This one is little-endian.]<br />
;<br />
; If you are expecting small values in the numerator or denominator, you can<br />
; check the high byte for 0 and do 8-bit shifts before doing the final 1-bit shifts.<br />
; Since the 8-bit-shift loop starts with a cmp [or tst] and a jump, the cost is<br />
; only about 13 cycles if it is not necessary. [Cypress cycles.]<br />
;<br />
; If you need to keep the remainder it gets a bit more complicated. The calculated<br />
; count, and the final calculated mask, will tell you where the remainder is in<br />
; the numerator: the remainder&#8217;s LSb is just above the highest 1-bit in the mask.<br />
; You may need to copy it out, mask and shift it before saving the quotient. You<br />
; can also contrive to save the quotient into a different word rather than into<br />
; the numerator, in which case you only need to shift the remainder back around.<br />
; However, this will cost you more shifts during the calculation [you need to<br />
; shift the numerator and the quotient separately].<br />
;<br />
; You can save yourself several bytes of RAM storage by calculating the final<br />
; mask on-the-fly.<br />
;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>div24by16::<br />
; Check for boundary conditions and set up the divide.<br />
mov        [dividend+3],0<br />
; Look for divide by zero.<br />
mov        a,[divisor+1]        ; See if the divisor is zero.<br />
or        a,[divisor]<br />
jnz        .divisor_not_zero<br />
; Divide by zero.<br />
mov        a,0xFF            ; Divide by zero? Get as close to infinity as we can.<br />
mov        [dividend],a<br />
mov        [dividend+1],a<br />
mov        [dividend+2],a<br />
ret</p>
<p>.divisor_not_zero:<br />
;divide.c: 62: }<br />
;divide.c: 63: shift_count = 1;<br />
mov        [shift_count],1+8            ; Difference in #bits between dividend and divisor. Plus 1.<br />
;divide.c: 64: while [[divisor &amp; 0x8000] == 0]<br />
jmp        .divisor_shift_start</p>
<p>.divisor_shift_loop:<br />
;divide.c: 65: {<br />
;divide.c: 66: ++shift_count;<br />
inc        [shift_count]<br />
;divide.c: 67: divisor &lt;&lt;= 1;<br />
asl        [divisor]<br />
rlc        [divisor+1]<br />
.divisor_shift_start:<br />
tst        [divisor+1],0b10000000<br />
jz        .divisor_shift_loop<br />
jmp        .dividend_shift_start</p>
<p>.dividend_shift_loop:<br />
;divide.c: 72: {<br />
;divide.c: 73: if [--shift_count == 0]<br />
dec        [shift_count]<br />
jnz        .l10<br />
;divide.c: 74: {<br />
;divide.c: 75: dividend = 0;<br />
mov        [dividend],0<br />
mov        [dividend+1],0<br />
mov        [dividend+2],0<br />
; dividend+3 is already zero.<br />
ret            ; Render the output and return.</p>
<p>.l10:<br />
;divide.c: 77: }<br />
;divide.c: 78: dividend &lt;&lt;= 1;<br />
asl        [dividend]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
; We&#8217;ll never shift anything into dividend+3 in this loop.<br />
.begin_continue:<br />
.dividend_shift_start:<br />
tst        [dividend+2],0b10000000        ; See if the high bit is set.<br />
jz        .dividend_shift_loop        ; If not, repeat until it is.<br />
;divide.c: 79: }<br />
;divide.c: 80: {<br />
;divide.c: 81: unsigned char mask_count = shift_count;<br />
mov        [mask_count],[shift_count]    ; shift_count is guaranteed to be at least 1.<br />
;divide.c: 82: mask = 0;<br />
mov        [mask],0<br />
mov        [mask+1],0<br />
mov        [mask+2],0<br />
;divide.c: 88: while [mask_count]<br />
.mask_shift_loop:<br />
;divide.c: 89: {<br />
;divide.c: 90: mask = [mask &lt;&lt; 1] | 1;<br />
asl        [mask]<br />
rlc        [mask+1]<br />
rlc        [mask+2]<br />
or        [mask],1<br />
;divide.c: 91: &#8211;mask_count;<br />
dec        [mask_count]<br />
jnz        .mask_shift_loop<br />
;divide.c: 92: }<br />
;divide.c: 93: }<br />
;divide.c: 94: do</p>
<p>.looping:<br />
;divide.c: 95: {<br />
;divide.c: 96: if [divisor &lt;= dividend]<br />
mov        a,[dividend+3]            ; Dividend has a higher byte than divisor.<br />
jnz        .dividend_is_bigger        ; If dividend high byte is non-zero, dividend is bigger by definition.<br />
mov        a,[divisor+1]<br />
sub        a,[dividend+2]<br />
jnz        .u925<br />
mov        a,[divisor]<br />
sub        a,[dividend+1]<br />
jz        .dividend_is_bigger<br />
.u925:<br />
jnc        .divisor_is_bigger        ; They&#8217;re not the same, see which one is bigger.<br />
.dividend_is_bigger:<br />
;divide.c: 97: {<br />
;divide.c: 98: dividend = [[dividend - divisor] &lt;&lt; 1] | 1;<br />
mov        a,[divisor]<br />
sub        [dividend+1],a<br />
mov        a,[divisor+1]<br />
sbb        [dividend+2],a<br />
sbb        [dividend+3],0<br />
asl        [dividend+0]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
rlc        [dividend+3]<br />
or        [dividend+0],1<br />
;divide.c: 99: }<br />
jmp        .l19</p>
<p>.divisor_is_bigger:<br />
;divide.c: 100: else<br />
;divide.c: 101: {<br />
;divide.c: 102: dividend = [dividend &lt;&lt; 1];<br />
asl        [dividend+0]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
rlc        [dividend+3]</p>
<p>.l19:<br />
;divide.c: 103: }<br />
;divide.c: 104: } while [--shift_count];<br />
dec        [shift_count]<br />
jnz        .looping<br />
.u950:</p>
<p>.l16:<br />
;divide.c: 105: dividend &amp;= mask;<br />
mov        a,[mask]<br />
and        [dividend],a<br />
mov        a,[mask+1]<br />
and        [dividend+1],a<br />
mov        a,[mask+2]<br />
and        [dividend+2],a<br />
mov        [dividend+3],0<br />
;divide.c: 106: }<br />
ret</p>
<p>;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
; Divide a 32-bit number by a 16-bit number. Leaves the quotient in the dividend<br />
; [numerator] and throws away the remainder.<br />
;<br />
; This works like a classic long division; it shifts the numerator and denominator<br />
; to the top of their respective words [so they are the same magnitude], counts<br />
; the number of shifts and uses it to calculate the number of subtracts needed as<br />
; well as the mask that eliminates the remainder.<br />
;<br />
; This can easily be extended or reduced to accomodate various word sizes. There<br />
; should be no problem dividing a smaller word by a larger, but you will have<br />
; to virtually extend the numerator with zeros. Since the initial shift factor will<br />
; start out negative you will need to fiddle with that; you do not want to quit<br />
; if you generate a carry, but instead test the sign of the result. [You still will<br />
; want to jump to .zero_quotient if the shift factor is negative. Note that a shift<br />
; factor of zero is valid.] [This version tests for zero, not carry, so that's<br />
; no longer true. Lowest valid shift factor is 1.]<br />
;<br />
; If you expect to be using long words or want to macro-ize this [or expect to<br />
; adapt it a lot] you may want to use multi-byte words and index into them<br />
; [e.g. [numerator+1] instead of discrete names for each byte. However, the result<br />
; will be endian-dependent. [This one is little-endian.]<br />
;<br />
; If you are expecting small values in the numerator or denominator, you can<br />
; check the high byte for 0 and do 8-bit shifts before doing the final 1-bit shifts.<br />
; Since the 8-bit-shift loop starts with a cmp [or tst] and a jump, the cost is<br />
; only about 13 cycles if it is not necessary. [Cypress cycles.]<br />
;<br />
; If you need to keep the remainder it gets a bit more complicated. The calculated<br />
; count, and the final calculated mask, will tell you where the remainder is in<br />
; the numerator: the remainder&#8217;s LSb is just above the highest 1-bit in the mask.<br />
; You may need to copy it out, mask and shift it before saving the quotient. You<br />
; can also contrive to save the quotient into a different word rather than into<br />
; the numerator, in which case you only need to shift the remainder back around.<br />
; However, this will cost you more shifts during the calculation [you need to<br />
; shift the numerator and the quotient separately].<br />
;<br />
; You can save yourself several bytes of RAM storage by calculating the final<br />
; mask on-the-fly.<br />
;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>div32by16::<br />
; Check for boundary conditions and set up the divide.<br />
mov        [dividend+4],0<br />
; Look for divide by zero.<br />
mov        a,[divisor+1]        ; See if the divisor is zero.<br />
or        a,[divisor]<br />
jnz        .divisor_not_zero<br />
; Divide by zero.<br />
mov        a,0xFF            ; Divide by zero? Get as close to infinity as we can.<br />
mov        [dividend],a<br />
mov        [dividend+1],a<br />
mov        [dividend+2],a<br />
mov        [dividend+3],a<br />
ret</p>
<p>.divisor_not_zero:<br />
;divide.c: 62: }<br />
;divide.c: 63: shift_count = 1;<br />
mov        [shift_count],1+16            ; Difference in #bits between dividend and divisor. Plus 1.<br />
;divide.c: 64: while [[divisor &amp; 0x8000] == 0]<br />
jmp        .divisor_shift_start</p>
<p>.divisor_shift_loop:<br />
;divide.c: 65: {<br />
;divide.c: 66: ++shift_count;<br />
inc        [shift_count]<br />
;divide.c: 67: divisor &lt;&lt;= 1;<br />
asl        [divisor]<br />
rlc        [divisor+1]<br />
.divisor_shift_start:<br />
tst        [divisor+1],0b10000000<br />
jz        .divisor_shift_loop<br />
jmp        .dividend_shift_start</p>
<p>.dividend_shift_loop:<br />
;divide.c: 72: {<br />
;divide.c: 73: if [--shift_count == 0]<br />
dec        [shift_count]<br />
jnz        .l10<br />
;divide.c: 74: {<br />
;divide.c: 75: dividend = 0;<br />
mov        [dividend],0<br />
mov        [dividend+1],0<br />
mov        [dividend+2],0<br />
mov        [dividend+3],0<br />
; dividend+4 is already zero.<br />
ret            ; Render the output and return.</p>
<p>.l10:<br />
;divide.c: 77: }<br />
;divide.c: 78: dividend &lt;&lt;= 1;<br />
asl        [dividend]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
rlc        [dividend+3]<br />
; We&#8217;ll never shift anything into dividend+4 in this loop.<br />
.begin_continue:<br />
.dividend_shift_start:<br />
tst        [dividend+3],0b10000000        ; See if the high bit is set.<br />
jz        .dividend_shift_loop        ; If not, repeat until it is.<br />
;divide.c: 79: }<br />
;divide.c: 80: {<br />
;divide.c: 81: unsigned char mask_count = shift_count;<br />
mov        [mask_count],[shift_count]    ; shift_count is guaranteed to be at least 1.<br />
;divide.c: 82: mask = 0;<br />
mov        [mask],0<br />
mov        [mask+1],0<br />
mov        [mask+2],0<br />
mov        [mask+3],0<br />
;divide.c: 88: while [mask_count]<br />
.mask_shift_loop:<br />
;divide.c: 89: {<br />
;divide.c: 90: mask = [mask &lt;&lt; 1] | 1;<br />
asl        [mask]<br />
rlc        [mask+1]<br />
rlc        [mask+2]<br />
rlc        [mask+3]<br />
or        [mask],1<br />
;divide.c: 91: &#8211;mask_count;<br />
dec        [mask_count]<br />
jnz        .mask_shift_loop<br />
;divide.c: 92: }<br />
;divide.c: 93: }<br />
;divide.c: 94: do</p>
<p>.looping:<br />
;divide.c: 95: {<br />
;divide.c: 96: if [divisor &lt;= dividend]<br />
mov        a,[dividend+3]            ; Dividend has a higher byte than divisor.<br />
jnz        .dividend_is_bigger        ; If dividend high byte is non-zero, dividend is bigger by definition.<br />
mov        a,[divisor+1]<br />
sub        a,[dividend+3]<br />
jnz        .u925<br />
mov        a,[divisor]<br />
sub        a,[dividend+2]<br />
jz        .dividend_is_bigger<br />
.u925:<br />
jnc        .divisor_is_bigger        ; They&#8217;re not the same, see which one is bigger.<br />
.dividend_is_bigger:<br />
;divide.c: 97: {<br />
;divide.c: 98: dividend = [[dividend - divisor] &lt;&lt; 1] | 1;<br />
mov        a,[divisor]<br />
sub        [dividend+2],a<br />
mov        a,[divisor+1]<br />
sbb        [dividend+3],a<br />
sbb        [dividend+4],0<br />
asl        [dividend+0]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
rlc        [dividend+3]<br />
rlc        [dividend+4]<br />
or        [dividend+0],1<br />
;divide.c: 99: }<br />
jmp        .l19</p>
<p>.divisor_is_bigger:<br />
;divide.c: 100: else<br />
;divide.c: 101: {<br />
;divide.c: 102: dividend = [dividend &lt;&lt; 1];<br />
asl        [dividend+0]<br />
rlc        [dividend+1]<br />
rlc        [dividend+2]<br />
rlc        [dividend+3]<br />
rlc        [dividend+4]</p>
<p>.l19:<br />
;divide.c: 103: }<br />
;divide.c: 104: } while [--shift_count];<br />
dec        [shift_count]<br />
jnz        .looping<br />
.u950:</p>
<p>.l16:<br />
;divide.c: 105: dividend &amp;= mask;<br />
mov        a,[mask]<br />
and        [dividend],a<br />
mov        a,[mask+1]<br />
and        [dividend+1],a<br />
mov        a,[mask+2]<br />
and        [dividend+2],a<br />
mov        a,[mask+3]<br />
and        [dividend+3],a<br />
mov        [dividend+4],0<br />
;divide.c: 106: }<br />
ret</p></div>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=34</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>More About Optimization</title>
		<link>http://baremetalblog.nonken.net/?p=31</link>
		<comments>http://baremetalblog.nonken.net/?p=31#comments</comments>
		<pubDate>Sun, 21 Feb 2010 07:25:38 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Programming Practices]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=31</guid>
		<description><![CDATA[Of course, the amount of optimizing you should do up front is really dependent on the situation. Generally you shouldn't optimize more than you have to until the code is working and reasonably stable.]]></description>
			<content:encoded><![CDATA[<p>Thanks for all the nice comments about my last post. It&#8217;s really gratifying to get so much praise so early.</p>
<p>I wanted to add a few thoughts. Kermit Derren says:</p>
<blockquote><p>I was studying something else about this on another blog&#8230; Your position on it is diametrically contradicted to what I read earlier.</p></blockquote>
<p>He&#8217;s not criticizing me, I left out some context, go back and read the whole comment. For that matter, neither am I criticizing him. It&#8217;s just that his comment made me think a little. I can&#8217;t comment directly on the other blog, not having read it (he didn&#8217;t provide a link). I want to emphasize that it&#8217;s possible that the other blogger is right, and that I&#8217;m also right, because what your priorities are depends very much on the situation.</p>
<p>My aforementioned former colleague who saved two bytes wasn&#8217;t so much misguided as he was just blindly following what he&#8217;d learned early in his career. He used to work in an industry where the resources were so thin and the timing so critical that the people who wrote the code knew every detail about every operation by heart, including all affected flags, any side-effects, and how many cycles they took to run. If there were any undocumented features they doubtless knew about those as well and used them. To these people finding two extra bytes was like discovering a new seam in what they thought was a played-out mine.</p>
<p>I&#8217;ve never lived in that world myself, though I&#8217;ve been closer than I am now. When you&#8217;re working in sub-1K memory space your priorities are different, believe me. So while I don&#8217;t know what the blog entry actually said, I&#8217;m willing to believe that an apparent disagreement might be due to a contextual difference. Then again, maybe he really believes that saving resources is a higher priority than writing clear, maintainable code in all circumstances. Until and unless Kermit shares the link I&#8217;m reduced to guesses.</p>
<p>Now&#8230; since I wrote &#8220;Optimize This!&#8221; I&#8217;ve watched my own habits more closely. I&#8217;ve found myself doing the very thing I&#8217;ve criticized &#8212; re-using variables with more of a thought to saving RAM (that I usually don&#8217;t need to save) than to program clarity. When I catch myself doing that of course I immediately repent and fix the problem. Hopefully I&#8217;ll break that habit soon and instill some better habits.</p>
<p>We are all of us hypocrites to some degree, and I am no exception, but I like to try not to be when I can help it.</p>
<p>A few days ago I had a programming situation where I had three conditions, each of which would cause a behavior (send a message) but were mutually exclusive (I can only send one at a time). I assigned each flag as a bit in a byte, with the higher priority as the higher value bit. Working in assembly there are a couple ways to do this:</p>
<ul>
<li>An if-then-else that tests each bit and decides whether to execute the associated code.</li>
<li>A jump table that depends on the value of the byte. It will of course double in size each time I add a bit.</li>
</ul>
<p>For only three flags I had eight values, so I made it a jump table. Jump tables are pretty fast. Then I discovered two more conditions, which meant that now I had thirty-two possible combinations that started to make the jump table look a bit daunting to create and maintain.</p>
<p>My first reaction was to make two jump tables and therefore two decisions, to keep the ROM usage down. Then I remembered my post and stopped to actually evaluate my situation. Once I thought it through the answer was obvious. I was using about 1/4 of my total ROM so far in a project that was mostly written. 48 extra bytes (two per jump) wasn&#8217;t going to make a dent in that, it was easier to maintain a single table than two tables plus glue logic, and it would take exactly the same number of execution cycles to deal with a 32-jump table as an 8-jump table. Instead of, say, three times as many cycles, if not more, if both tables were executed. As far as generating the table goes, well, I put it together using one of my favorite tools &#8212; Excel (or an open source alternative &#8212; usually Open Office or Gnumeric). This made generating redundant entries (and counting them) and re-arranging priorities much simpler to do without making mistakes (once I had the equations fine-tuned, of course).</p>
<p>Of course writing the Excel equations can take more time than just writing the bloody thing by hand, but it&#8217;s less tedious and, as I mentioned, less prone to making mistakes &#8212; especially when I change things around, because if I design the spreadsheet well enough, I can change things around and the table just automatically gets fixed.</p>
<p>In any case, I was much happier with the result.</p>
<p>I really like using a spreadsheet for generating (and sometimes maintaining) lists of things. You can, for example, generate the lookup table for a curve, including DB (Define Byte) statements and tabs and comments if need be, in Excel and then copy/paste the result directly into your source code. If you make a change it just re-calculates and you just copy/paste again. Excel has some nice table lookup functions too, string manipulation, and decimal/hex conversion. You don&#8217;t really need to be an expert &#8212; learn a few tricks and you&#8217;re halfway there. I depend a lot on the built-in help and on web searches when I&#8217;m trying to learn a new feature, but none of it is difficult. Read this article by Joel Spolsky called <a title="The Process of Designing a Product" href="http://www.joelonsoftware.com/uibook/chapters/fog0000000065.html" target="_blank">&#8220;The Process of Designing a Product&#8221;</a>. About halfway down he talks about discovering that people mostly use Excel to keep lists. It&#8217;s certainly true in my case, and I&#8217;m glad they focused on that functionality as a result.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 552px; width: 1px; height: 1px;">ℼ佄呃偙⁅瑨汭倠䉕䥌⁃ⴢ⼯㍗⽃䐯䑔堠呈䱍ㄠ〮吠慲獮瑩潩慮⽬䔯≎ऊ∉瑨灴⼺眯睷眮⸳牯⽧剔砯瑨汭⼱呄⽄桸浴ㅬ琭慲獮瑩潩慮⹬瑤≤ਾ格浴⁬浸湬㵳栢瑴㩰⼯睷⹷㍷漮杲ㄯ㤹⼹桸浴≬砠汭氺湡㵧攢≮氠湡㵧攢≮ਾ格慥㹤ऊ琼瑩敬吾扡敬㱳琯瑩敬ਾ洼瑥⁡瑨灴攭畱癩∽潃瑮湥⵴祔数•潣瑮湥㵴琢硥⽴瑨汭※档牡敳㵴瑵ⵦ∸⼠ਾ㰉ⴡ‭䜢偟啌䥇彎但归呈䱍•ⴭਾ猼祴敬琠灹㵥琢硥⽴獣≳ਾ瑴笠ऊ潦瑮昭浡汩㩹挠畯楲牥਻੽摴笠ऊ潦瑮昭浡汩㩹栠汥敶楴慣‬慳獮猭牥晩਻੽慣瑰潩⁮੻昉湯⵴慦業祬›敨癬瑥捩ⱡ猠湡⵳敳楲㭦ऊ潦瑮猭穩㩥ㄠ瀴㭴ऊ整瑸愭楬湧›敬瑦਻੽⼼瑳汹㹥㰊栯慥㹤㰊潢祤ਾ瀼⼠㰾慴汢⁥散汬灳捡湩㵧〢•散汬慰摤湩㵧㌢㸢㰊牴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰰琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢潮愠瑣潩㱮琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻〾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㬾丠瑯楨杮琠⁯潤㰡琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰱琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢䕒佐呒偟协呉佉㱎琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤潰楳楴湯⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰱琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤潰楳楴湯⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻刾偅剏彔䕓噒彏䥔䕍⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮獟牥潶瑟浩㱥琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮獟牥潶瑟浩㱥琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰴琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢䕒佐呒䵟呏剏呟䵉㱅琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤潭潴彲楴敭⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰳琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤敳癲彯楴敭⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㠾⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻刾偅剏彔䥌䥍㱔琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤楬業㱴琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㐾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮浟瑯牯瑟浩㱥琯㹤㰊摴挠汯灳湡∽∴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢※敓摮洠瑯牯琠畲灭⁳敳摮猠牥潶㰮琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㘱⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻䰾十彔䅖啌彅䕐䑎义㱇琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㔾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮浟瑯牯瑟浩㱥琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰶琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤潭潴彲楴敭⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㜾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮浟瑯牯瑟浩㱥琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㰸琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤楬業㱴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴挠汯灳湡∽∶†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢※敓摮氠浩瑩琠畲灭⁳敳摮瀠獯瑩潩⁮牯洠瑯牯猠数摥⹳⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㤾⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮江浩瑩⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻ㄾ㰰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤楬業㱴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢ㄱ⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮江浩瑩⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻ㄾ㰲琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤楬業㱴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㌱⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮江浩瑩⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻ㄾ㰴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢献湥彤楬業㱴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㔱⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻⸾敳摮江浩瑩⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻ㄾ㰶琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴挠汯灳湡∽∴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢※慗瑩湩⁧潦⁲牰癥潩獵瘠污敵琠⁯敳摮㰮琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㜱⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻ㄾ㰸琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㤱⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾㰰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢ㄲ⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾㰲琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㌲⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾㰴琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㔲⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾㰶琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㜲⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㈾㰸琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢㤲⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ琼㹲㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽楲桧≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻㌾㰰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢浪㱰琯㹤㰊摴挠汯灳湡∽∲†慶楬湧∽潢瑴浯•愠楬湧∽敬瑦•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢敮瑸獟整㱰琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊摴†瑳汹㵥∢㰾琯㹤㰊琯㹲㰊牴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮爢杩瑨•猠祴敬∽映湯⵴楳敺ㄺ瀱㭴㸢ㄳ⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻樾灭⼼摴ਾ琼⁤潣獬慰㵮㈢•瘠污杩㵮戢瑯潴≭†污杩㵮氢晥≴†瑳汹㵥•潦瑮猭穩㩥ㄱ瑰∻渾硥彴瑳灥⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ琼⁤猠祴敬∽㸢⼼摴ਾ⼼牴ਾ⼼慴汢㹥㰊戯摯㹹㰊栯浴㹬 ഀ䫄൵䥴൵�൱而൰�൱�൱�൱而൰ȴ൲Ɍ൲�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰ผ൲ิ൲�൱而൰�൱�൱�൱而൰൱劼൲�൱而൰䫜൵䫴൵䬌൵䬤൵䬼൵䭔൵䭬൵䮄൵䮜൵䮴൵䯌൵䯤൵䯼൵䰔൵䰬൵䱄൵䱜൵䱴൵䲌൵�൱而൰�൱�൱�൱而൰൱≴൲�൱而൰�൱�൱�൱而൰൱㔄൲�൱而൰�൱�൱�൱而൰�൱处൲�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰൱妔൲�൱而൰�൱�൱�൱而൰�൱䴄൲�൱而൰�൱�൱�൱而൰�൱㘼൲�൱而൰�൱�൱�൱而൰�൱⢼൲�൱而൰�൱�൱�൱而൰�൱Ẵ൲�൱而൰�൱�൱�൱而൰�൱ු൲�൱而൰�൱�൱�൱而൰൱ﻔ൱�൱而൰�൱�൱�൱而൰�൱൱�൱而൰�൱�൱�൱而൰�൱⟌൲�൱而൰�൱�൱�൱而൰൱௜൲�൱而൰�൱�൱�൱而൰൱ﵬ൱�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰�൱൱�൱而൰�൱�൱�൱而൰�൱�൱䲤൵�൱䲼൵䳔൵�൱䲼൵�൱而൰�൱�൱�൱而൰�൱൱䳬൵�൱䴄൵൱而൰�൱�൱൱而൰�൱䯌൲�൱而൰�൱�൱�൱尼൰൱�൱而൰�൱�൱�൱而൰˴൲಴൲�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰ᢴ൲⭴൲�൱而൰�൱�൱�൱而൰᱄൲ᱜ൲�൱而൰�൱�൱�൱而൰巤൲巼൲�൱而൰�൱�൱�൱而൰Ӕ൲Ӭ൲�൱而൰�൱�൱�൱而൰幜൲年൲�൱而൰�൱�൱�൱而൰弜൲弴൲�൱而൰�൱�൱�൱而൰䮄൲䮜൲�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰“൲‴൲�൱而൰�൱�൱�൱而൰Д൲Ь൲�൱而൰�൱�൱�൱而൰ൄ൲൜൲൱而൰�൱�൱൱而൰൱൱�൱而൰�൱�൱�൱而൰庌൲庤൲⺼൵而൰൱而൰�൱�൱൱而൰�൱㥔൲�൱而൰�൱�൱�൱而൰㶤൲㶼൲�൱而൰�൱�൱�൱而൰公൲�൱而൰�൱�൱�൱而൰☄൲☜൲�൱而൰�൱�൱�൱而൰Ỽ൲ἔ൲�൱而൰�൱�൱�൱而൰᠌൲ᠤ൲�൱而൰�൱�൱�൱而൰൱൱�൱而൰�൱�൱�൱而൰൱൱而൰垔൱垔൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱�൱㚼൹㛔൹㛬൹㜄൹㜜൹㜴൹㝌൹㝤൹㝼൹㞔൹㞬൹ᴌ൹쩜൸�൱而൰牼൷�൱而൰皴൷盌൷尼൰䒬൲盤൷盼൷錔൶ޜൺ޴ൺ�൱而൰붔൴붔൴而൰�൱�൱ᙄ൲而൰붬൴뷄൴뷜൴뷴൴브൴븤൴븼൴빔൴빬൴뺄൴뺜൴뺴൴뻌൴뻤൴뻼൴뼔൴뼬൴뽄൴뽜൴뽴൴뾌൴뾤൴뾼൴뿔൴뿬൴쀄൴쀜൴쀴൴쁌൴쁤൴쁼൴삔൴사൴샄൴샜൴�൱㒔൰㒔൰噜൱噜൱�൱而൰ߌൺ�൹䥴൵ߤൺ߼ൺ�൱ꃜ൶疔൷疔൷൷㟄൹㟜൹㟴൹㠌൹㠤൹㠼൹㡔൹㡬൹㢄൹㢜൹⺼൵而൰�൱而൰䒬൲ￄ൷๬൳�൱而൰嗜൰൷ل൳�൱而൰暌൰൷Ӝ൳�൱而൰璄൰൷ӄ൳�൱而൰嘼൰൷Ҭ൳�൱而൰蘤൰൷Ҕ൳�൱而൰䏴൰൷Ѽ൳�൱而൰㏔൰൷Ѥ൳�൱而൰叼൰൷ь൳�൱而൰獤൰൷д൳�൱而൰䯬൰൷М൳�൱而൰勴൰൷Є൳�൱而൰乄൰൷Ϭ൳�൱而൰膤൰൷ϔ൳�൱而൰㪔൰൷μ൳�൱而൰佤൰൷Τ൳൷�൱而൰佤൰൷Ό൳�൱而൰佤൰൷ʹ൳�൱而൰犌൰൷͜൳�൱而൰涬൰൷̈́൳�൱而൰䬔൰൷̬൳൷�൱而൰禔൰൷̔൳�൱而൰禔൰൷˼൳�൱而൰琤൰൷ˤ൳�൱而൰袬൰൷ˌ൳�൱而൰姤൰൷ʴ൳�൱而൰搴൰൷ʜ൳൷�൱而൰搴൰൷ʄ൳�൱而൰搴൰൷ɬ൳�൱而൰苄൰൷ɔ൳�൱而൰䐌൰൷ȼ൳�൱而൰誤൰൷Ȥ൳�൱而൰舄൰൷Ȍ൳�൱而൰抴൰൷Ǵ൳�൱而൰牄൰൷ǜ൳�൱而൰歔൰൷Ǆ൳�൱而൰㺜൰൷Ƭ൳�൱而൰煬൰൷Ɣ൳�൱而൰㗌൰൷ż൳�൱而൰㒔൰൷Ť൳�൱而൰脜൷൷Ō൳�൱而൰脜൷൷Ĵ൳�൱而൰贬൰൷Ĝ൳�൱而൰㒔൰൷Ą൳�൱而൰㼌൲㹴൷㺌൷㺤൷㺼൷㻔൷㻬൷㼄൷㼜൷㼴൷㽌൷㽤൷㽼൷㾔൷㾬൷㿄൷㿜൷㿴൷䀌൷䀤൷䀼൷䁔൷䁬൷㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲㸔൷㺔൲ぼ൷�൱㻄൲つ൷�൱㻄൲㸬൷�൱㻄൲ﴄ൶�൱㻄൲㻄൲溔൲陴൰�൱�൱㻄൲隤൰䂌൲䂤൲䂼൲溬൲䏔൲䥜൲䓄൲䥴൲䦤൲滄൲坌൱�൱而൰壼൱�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲�൱㻄൲ﴜ൶�൱㻄൲㹄൷�൱㻄൲㹜൷�൱㻄൲ゔ൷�൱㻄൲�൱㻜൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱㼌൲�൱而൰㼤൲䂄൷䂜൷䂴൷䃌൷䃤൷䃼൷䄔൷䄬൷䅄൷䅜൷䅴൷䆌൷䆤൷䆼൷䇔൷䇬൷䈄൷䈜൷䈴൷䉌൷䉤൷䉼൷䊔൷䊬൷䋄൷䋜൷䋴൷䌌൷䌤൷䌼൷䍔൷䍬൷䎄൷䎜൷䎴൷䏌൷䏤൷䏼൷䐔൷䐬൷䑄൷䑜൷䑴൷䒌൷䒤൷䒼൷䓔൷�൱㼤൲�൱㼤൲�൱㼤൲�൱而൰㼼൲䓬൷䔄൷䔜൷䔴൷䕌൷䕤൷䕼൷䖔൷�൱而൰㽔൲䖬൷䗄൷䗜൷䗴൷䘌൷䘤൷猀Փ铘=�ԪṀԎ倴਱싔੏值਱뵴Խ獀Փ铘=�ԪṀԎ偌਱殤̃偔਱분Խ玀Փ铘=�ԪṀԎ偤਱鈄©偬਱붤Խ酀Չ齰=뻠Ў䤠ਦ袉ҹ́й̱й</div>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=31</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Look to the Edges</title>
		<link>http://baremetalblog.nonken.net/?p=24</link>
		<comments>http://baremetalblog.nonken.net/?p=24#comments</comments>
		<pubDate>Wed, 16 Dec 2009 08:22:53 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Programming Practices]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=24</guid>
		<description><![CDATA["We look to... the edges," said Mistress Weatherwax. "There're a lot of edges, more than people know. Between life and death, this world and the next, night and day, right and wrong... an' they need watchin'. We watch 'em, we guard the sum of things."]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;And what do you really do?&#8221; said Tiffany.</p>
<p>The thin witch hesitated for a moment, and then:</p>
<p>&#8220;We look to&#8230; the edges,&#8221; said Mistress Weatherwax. &#8220;There&#8217;re a lot of edges, more than people know. Between life and death, this world and the next, night and day, right and wrong&#8230; an&#8217; they need watchin&#8217;. We watch &#8216;em, we guard the sum of things.&#8221;</p></blockquote>
<p>We programmers need to watch the edges, too. Different edges, perhaps, but nevertheless there&#8217;re a lot of edges, more than people know.</p>
<p>Back in the &#8217;90s I was administrating a backup system with about 180 client computers. One day it started going wonky. (I don&#8217;t remember in what fashion.) I couldn&#8217;t figure out why, so naturally I called tech support.</p>
<p>After I described the problem, the support tech said, &#8220;What did you change?&#8221; I didn&#8217;t change anything. &#8220;You <em>must </em>have changed something, it was working before and it&#8217;s not working now. What have you changed in the last few days?&#8221; Certainly the code didn&#8217;t change, and it obviously worked, so the fault must lie in the customer. He was very insistent and barely polite.</p>
<p>We did not solve the problem during that phone call.</p>
<p>Two days later an upgrade came out. It seems that when the catalog file grew over 2GB it started having problems. The upgrade fixed that problem. (I don&#8217;t remember, but I&#8217;ll bet it extended it to 4GB. If you run the numbers I think you&#8217;ll find that 2GB is exactly the same as the highest value you can fit into a signed 32-bit integer. What a coincidence!)</p>
<p>What did I change in those few days? Depends on your point of view; all I changed was the amount of data in the catalog, and that was by running the system exactly as I had been. Really I didn&#8217;t change anything, but things did change, and the program simply couldn&#8217;t keep up.</p>
<p>It&#8217;s a perfect illustration of edge conditions that we all should watch. Can the index overflow a word? Will the size of that value really, really work for all eternity, or just for the foreseeable future? Watch out for statements like &#8220;Nobody will EVER fill that up!&#8221; I heard that in 1982 about 5 megabyte hard drives. Nobody will ever fill that up. Heh. Now you can buy 5 terabytes for a few hundred dollars and carry it around in a couple decent-sized coat pockets. It won&#8217;t be long before you can buy it in a single drive for under $100. And nobody with any sense will tell you that you&#8217;ll never fill it up.</p>
<p>One very typical programming error is called an off-by-one error, which usually happens when you&#8217;re working with zero-based indexes and one-based sizes and lose track of which is which. You can consider this a kind of edge condition; it certainly causes edge-condition-type errors. You can easily copy one too few or one too many items, or simply index past the end of your data. By one. Or never quite reach it. By one.</p>
<p>It&#8217;s easy to find those edges in small embedded systems where you typically use as small a variable as you can get away with. I use single-byte words all the time. How often do I use 32-bit integers? Pretty gosh darn seldom. But 32-bit signed integers are the default for the C++ compiler I use for PC programming. It&#8217;s actually more efficient to let it default to 32-bit integers than to use bytes, because the native word on the Pentium-class processor is 32 bits. Using anything smaller just makes the system work harder, and it will probably allocate 32 bits anyway because it wants things to align nicely. You probably have to tell it to pack your structs if you want to use them outside the program.</p>
<p>It&#8217;s enough to make an 8-bit processor guy cry (for envy) into his special sheep liniment.</p>
<p>What really tends to sneak up to you, though, and bite you on the backside is when you convert or calculate or otherwise change from one word size to another. This happens often when you try to have two different sized systems talking to each other, though of course it can also happen within your small system. It also happens when you get sloppy programmers writing code that uses the minimum needed (but different) size for each variable and then willy-nilly does calculations and copies and indexes back-and-forth without even bothering to cast anything. Of course this guy uses a low warning level when he compiles. And then he leaves the job and you&#8217;re left trying to figure out why the code is so buggy. Or rather, <em>why</em> it&#8217;s buggy is obvious, but you have to find and kill the bugs.</p>
<p>My current job is all about PC-based flight simulator software exchanging data with simulator hardware that&#8217;s based on 8-bit micros. Fortunately most of the actual data are flowing from the hardware to the flight sim software; most of the time the data are going from 10 bits to floating point, and the probability of messing up the scaling is much, much higher than the possibility of losing your high bits.</p>
<p>On the other hand, some of the controls don&#8217;t use the full range of the sensors and so must be calibrated. Since the sensor in this case is probably a cheap potentiometer, the wires pick up noise, there&#8217;s noise on the power supply, noise introduced by the multiplexers, and noise in the A/D conversion, the value tends to jump around a little. So even the most careful calibration won&#8217;t guarantee that the incoming value will never exceed my calibrated limits unless I&#8217;m really fanatical or add some padding. Which I don&#8217;t really want to do  in this case.</p>
<p>What&#8217;s that all mean? It means the incoming data will probably exceed my edges, eventually. In this case I simply check the value against the end-points, and if it&#8217;s out of range I rail it.</p>
<p>But I do check.</p>
<blockquote><p>&#8220;But there&#8217;s magic, too. You&#8217;ll pick that up. It don&#8217;t take much intelligence, otherwise wizards wouldn&#8217;t be able to do it.&#8221;</p></blockquote>
<p>It&#8217;s not enough to be a <a href="http://www.sdtimes.com/link/25499" target="_blank">wizard</a>. You need to be a witch, and look to the edges.</p>
<hr />Quotes and the reference to <a href="http://wiki.lspace.org/wiki/Sarah_Aching" target="_blank">Special Sheep Liniment</a> are from <a href="http://en.wikipedia.org/wiki/The_Wee_Free_Men" target="_blank"><em>The Wee Free Men</em></a>, a novel of the <a href="http://www.terrypratchettbooks.com/discworld/" target="_blank">Discworld</a> by Terry Pratchett.</p>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimize This!</title>
		<link>http://baremetalblog.nonken.net/?p=22</link>
		<comments>http://baremetalblog.nonken.net/?p=22#comments</comments>
		<pubDate>Fri, 16 Oct 2009 06:27:24 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Programming Practices]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=22</guid>
		<description><![CDATA[Tiny embedded systems often need more up-front optimization than PC applications. But even here too much too soon can be wasted work and, worse, obfuscate code and make it unmanageable.]]></description>
			<content:encoded><![CDATA[<p>Mostly when I write code these days I write in assembly language on 8-bit systems. And I like it. That&#8217;s how sick I am. <img src='http://baremetalblog.nonken.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was working on a project and needed a small function written. I knew what it needed to do, but I wasn&#8217;t sure how to do it. My colleague <em>did</em> know how to do it, so I asked him to write it for me, figuring it would be easier to wrap my head around something I could see, and it would get done more quickly this way.</p>
<p>This (now former) colleague used to write gaming software and firmware. We&#8217;re not talking PS3 or XBox here, we&#8217;re talking the old stuff, a couple K (if that) of ROM and a handful of bytes of RAM with no performance to speak of animating games on video. These guys used to know not only every instruction of the CPU but the number of bytes and number of cycles every instruction took, what flags were affected for every operation, and so on. They practically lived inside the machines. I don&#8217;t know if he himself was that intense but he was at least very close, and worked with the guys who were.</p>
<p>So I got the function back and started studying it. The first thing I asked was, &#8220;What is &#8216;cs&#8217;?&#8221; <strong>cs</strong> was the name of a two-byte checksum  used in virtually all our code (most projects were similar, so derived from each other). He was using <strong>cs</strong> and <strong>cs+1</strong> in several places. &#8220;It&#8217;s a counter,&#8221; he said, &#8220;obviously&#8221; he didn&#8217;t quite say. &#8220;<strong>cs</strong> is a checksum. Why use that instead of creating a new variable?&#8221; &#8220;Well, it saved two bytes.&#8221;</p>
<p>I was incredulous. &#8220;Colleague,&#8221; said I, &#8220;this part has 256 bytes of RAM and we&#8217;re using about 120, less than half. Why on Earth did you need to save two bytes?&#8221;</p>
<p>He didn&#8217;t really have an answer. He&#8217;d never bothered to check; saving two bytes was as automatic as breathing to him. When I write code I ask myself, &#8216;Will this work, is it maintainable, what comments should I add, how should I name the labels, how does it fit in with the rest of the code, is it efficient&#8217;, stuff like that. When he writes code the only question he asks is &#8216;Can I save two bytes?&#8217;</p>
<p>Re-using variables that are out-of-scope is a time-honored tradition, necessary when your resources are extremely scarce, and fraught with danger. It is far too easy to think a variable is being used in two disjoint scopes when in fact the scopes overlap in unexpected ways. Doing it when it&#8217;s required is a necessary evil. Doing it when you have mostly-finished code that&#8217;s using less than half the RAM is inexcusable.</p>
<p>But that wasn&#8217;t his only crime. In assembler it&#8217;s very easy to attach multiple labels to the same address. Yes, part of the problem was re-using variables when it wasn&#8217;t necessary. But another part was using variable names that made no sense. To him, maintainable code is code he wrote. He knows how it works, therefore it&#8217;s obvious how it works, therefore it&#8217;s maintainable. But when I started to study the code I saw &#8220;cs&#8221; and thought &#8220;checksum&#8221; because that&#8217;s what that variable was. Even when I knew it was a counter it was hard for me to shift paradigms. What was worse was that he was using both bytes of <strong>cs</strong> as two different counters in that code, and they both had the same label with a different offset. Even given his passion for saving two bytes he should have added new label names to those bytes and used the related labels. (And added a comment that he was re-using <strong>cs</strong>.)</p>
<p>I created two appropriately-named variables and altered the code accordingly. Suddenly the code was quite simple to understand, given that I already knew what it was supposed to do. It went from opaque to clear that easily.</p>
<p>Books like Code Complete will point out that optimizing first is counter-productive. And they have a point.</p>
<ul>
<li>When you&#8217;re writing the code, you don&#8217;t really know where the bottlnecks are. Oh, you can make an educated guess, but it&#8217;s amazing how often those guesses are completely off the mark.</li>
<li>It&#8217;s more important to get the code working <em>first</em>. Optimizing bad code just means it will be wrong with fewer resources, except the time you spent optimizing it. Now you have to fix the code, and chances are it will break the optimization you&#8217;ve performed. It may even get thrown out. And it&#8217;s even possible that you broke it by optimizing it!</li>
<li>Any programmer with experience will know that a lot of their code will be radically changed or even thrown out before the project is finished. Even if it works perfectly as written, what&#8217;s needed may change.</li>
</ul>
<p>So the lesson is: get it working first. Optimize later.</p>
<p>Which is great advice. But what if you&#8217;re working on a tiny processor with few resources? <em>If the code doesn&#8217;t fit, it doesn&#8217;t matter if it&#8217;s right. It can&#8217;t work!</em></p>
<p>This is one of the places where general programming advice doesn&#8217;t quite fit in the embedded world. Mind you, it&#8217;s not <em>wrong</em>. It&#8217;s just not quite the black-and-white area it is when you have a PC with virtually unlimited resources.</p>
<p>So when you&#8217;re writing code for small processors you get into certain habits. Despite my outrage at my colleague&#8217;s mindless need to save resources we quite positively had more than enough of, I do understand it. It&#8217;s just that it should not have <em>been</em> mindless. He should have stopped to consider: I can save two bytes here. <em>But do I need to? </em>Should<em> I?</em> The answer being a resounding NO this time. &#8230;And had we been tight on RAM, then it might have been worth doing.</p>
<p>It&#8217;s a constant background hum, thinking about where to save a byte or two, what is the fastest way to do this, can I re-use the common part of this code by jumping into the middle, and so on. And sometimes I run out of something and have to optimize or find another way to do it.</p>
<p>There&#8217;s a funny psychological twist to that, too. I&#8217;ll be going along, resisting temptation to optimize as I write, and then run out of ROM. Then I&#8217;ll have to spend time optimizing so it will fit &#8212; and I&#8217;ll resent that time spent, feeling bitter about not having done the optimization in the first place, and if I had, see? I wouldn&#8217;t have to do this &#8212; completely forgetting the fact that I&#8217;m now only using time I&#8217;d previously saved by not optimizing prematurely.</p>
<p>Do I have any specific advice? I&#8217;m not really sure I do. The balance depends on a lot of factors, not the least of which is how much room do you have vs. how big is the project? Mostly I would be inclined to repeat what I&#8217;ve already said, some of which is really just channeling folks with more experience than I. Don&#8217;t automatically optimize from the start. Try to keep the code elegant. Think about it as you go, keep it in the back of your mind. Don&#8217;t be afraid to throw code away. Don&#8217;t be afraid to go back and tighten up or re-write code.  Accept that if you can&#8217;t optimize the code to fit, maybe there just isn&#8217;t room for the functionality. Or maybe there is using the old techniques, but is it worth making code that&#8217;s impossible to maintain?</p>
<p>Generally the highest cost in software development is maintenance. Spend a bit of time up front to make the code clean and elegant and you&#8217;ll save time down the road.</p>
<p>Don&#8217;t save two bytes at the cost of clarity and robustness just because you can.</p>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=22</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>&#8220;Quality is designed in, not added on.&#8221;</title>
		<link>http://baremetalblog.nonken.net/?p=17</link>
		<comments>http://baremetalblog.nonken.net/?p=17#comments</comments>
		<pubDate>Wed, 16 Sep 2009 07:05:45 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Programming Practices]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://baremetalblog.nonken.net/?p=17</guid>
		<description><![CDATA[I&#8217;ve been using that quote as my e-mail sig for about a year now. Actually, I think I made that one up myself. It started out as something more like &#8220;Quality is something you design in from the start, not tack on at the end.&#8221; But I like to keep my sigs short and sweet [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using that quote as my e-mail sig for about a year now. Actually, I think I made that one up myself. It started out as something more like &#8220;Quality is something you design in from the start, not tack on at the end.&#8221; But I like to keep my sigs short and sweet when I can.</p>
<p>Think about it. First, make a cheap piece of crap. Then QA it. Run it through tests, tighten loose screws, replace the broken buttons. When you&#8217;re done you have a cheap piece of crap that worked just before you put it into the box.</p>
<p>QA certainly didn&#8217;t add any quality, no matter how heroic their efforts. All they did was make sure that one item worked once. As soon as it shows on the doorstep of a real person all bets are off. If it&#8217;s a product you&#8217;re trying to support, your support costs are going to go through the roof.</p>
<p>Software is no different from any other product. If you toss it together without thought or planning, what you end up with may work today, but tomorrow somebody is going to enter &#8220;32q&#8221; into a numeric field, or slide the mechanism just a little too quickly, or try to open a jpeg file instead of ASCII text, and suddenly your program will crash and take the customer&#8217;s next month&#8217;s payroll with it.</p>
<p>Of course, with enough effort you can bash it into good enough shape that the bugs will be minor annoyances, and people will work around them. Then next week somebody will ask for a new feature and you&#8217;ll say &#8220;Sure!&#8221; or somebody will report a bug you can&#8217;t ignore. Now you have to go back into the code and improve it. When you fix one thing, do three others break? Do you have Heisenbugs that inexplicably vanish one day and show up the next? Does the very idea of working on your code make your hands go all clammy and make you think of long vacations in Tahiti? What you have there, my friend, is code that is both fragile and unmaintainable.</p>
<p>Maintenance and support are probably going to be your biggest expenses. The only way you&#8217;re going to keep them tolerable is by designing quality in from the start. Make the product more robust and the customers won&#8217;t be calling as often, for as long. Fewer RMAs. Make the product more maintainable and it will cost less to add those important features and fix those important bugs.</p>
<p>Here are a few ways to help assure quality in your software.</p>
<p><strong>Proper Documentation</strong></p>
<p>Document how it&#8217;s supposed to look to the customer, how it&#8217;s supposed to work, and what it does when things go wrong. Everybody signs off on it. If anybody wants a change it has to go into the document first, and the schedule gets adjusted accordingly. Too much rush, too many direction changes, too much pressure will be reflected in the quality of the code.</p>
<p><strong>Proper scheduling</strong></p>
<p>Scheduling is one of the worst problems in software. Part of it is pressure; bosses like optimistic estimates and will likely apply pressure to that end. Technically-oriented bosses may be more enlightened, but they may not &#8212; a mediocre programmer, perhaps one who came from a culture of hack-and-slash programming, may reject estimates that he &#8220;knows&#8221; are too long because he knows how long it would take him to write it. He&#8217;s actually ignoring the time it takes to get it working, and not thinking at all about maintainability.</p>
<p>My favorite method is: Break it down into tasks. Pick a minimum time for a task: I usually use one day. Estimate the time for each task; double it for debugging and other chores. If it&#8217;s less than your minimum, make it your minimum. Don&#8217;t be afraid to add some padding to any task you&#8217;re unsure about.</p>
<p>It works surprisingly well. What happens is most of those one-hour tasks actually only take an hour or two, and suddenly I&#8217;m three days ahead. Then I run smack dab into a problem on one of the two-day tasks that takes three days to sort out. In the end I find that I usually break even, plus or minus a little.</p>
<div>You don&#8217;t have to use my method. Use what works for you, but I emphasize, what <em>works</em> for you. If a method keeps coming up short (seldom will you regularly over-estimate!) then either adjust the method or try another one. Try mine if you like, or go online and find the other ten thousand three hundred ways of doing it. People write books about it.</div>
<div>Some of this folds back into what I said earlier.  Any time there&#8217;s a change in the design it needs to be added to the estimate. Don&#8217;t be tempted to write small changes off; every one will cost you, and other people will be tempted to ask for a lot of them. Small changes have a habit of becoming big pains in the neck, so consider carefully what the side-effects will be.</div>
<div><strong>Keep in practice</strong></div>
<div>&#8220;But it&#8217;s only a quick utility for my own use. It&#8217;s not worth spending a lot of time on.&#8221; Quite often that&#8217;s true; it may not be worth spending a lot of time polishing a one-time-use utility or something only used occasionally or as part of the actual development. But watch out: if people find it useful it may get out into the wild. <a href="http://jeffrey.nonken.net/doku.php?id=analect_instruments#format_and_backup" target="_blank">It&#8217;s happened to me.</a> If you spend a bit of time on that quality, it&#8217;ll be something to be proud of instead of something you&#8217;re constantly apologizing for.</div>
<div>And it will help keep you in the habit of building in quality. The great thing about a habit is that you don&#8217;t have to think about doing; you just do it.</div>
<div><strong>Break down; simplify; separate<br />
</strong></div>
<div>I&#8217;m an assembly language programmer, mainly. I also work in C and C++.  (I know other languages and can learn others, but those are what I happen to work in at the moment.) I&#8217;m not a great C++ guru by any means. I have mixed feelings about many of its features.</div>
<div>But I <em>love</em> C++ for some things. Encapsulation. Data hiding. Accessors. Abstraction. These are things either directly part of the language or strongly supported by it. These are things that you can do in C, in a sense, in a crippled sort of way. (My other favorite feature of C++ over C is the more rigid typing.)</div>
<div>Assembly doesn&#8217;t give you that sort of structure. But you can impose much of it yourself, and I do. I isolate functionality into single modules (one source file, usually with one associated include file). Is it a display function? Create a module called &#8220;display&#8221; and move all the functionality for the display into that module. All the variables should be local if possible. If you need external access, create accessor functions. Compromise only where performance is a serious issue, and make &#8220;gentleman&#8217;s agreement&#8221; rules to limit access. Macros are good for that, too.</div>
<div>In my current job I inherited a piece of code that I eventually turned into our current crop of products. During the process I noticed that the USB code had some flakiness that was hard to define and not obvious in a quick code review. One day I decided it was time to track it down. What was the first thing I did? Not the emulator. Not a formal code review. The first thing I did was pull in all the related variables that were defined in other modules, made public variables local and write accessor functions, pull inline code from other modules and turn it into accessor functions, and generally encapsulated the code. I compiled it, swept away a few bugs, and tried it.</div>
<div>The flakiness was gone. Poof, like magic. I never followed up on the original symptoms and in nearly a year it has never shown up again. This same code is being used in every single one of our (new USB version) major products. All I did was make absolutely sure everything that happened to the USB code and its variables was under strict control of that module, and the robustness of that module jumped by several orders of magnitude. The other effect of doing that was, of course, that it made the module more maintainable &#8212; everything pertaining to USB is in that module. If I have to make a change I don&#8217;t need to poke around all over the place trying to find the bits and pieces; it&#8217;s all there.</div>
<div>And I didn&#8217;t even use classes.</div>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good for now</title>
		<link>http://baremetalblog.nonken.net/?p=10</link>
		<comments>http://baremetalblog.nonken.net/?p=10#comments</comments>
		<pubDate>Tue, 08 Sep 2009 02:00:23 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Meta-blogging]]></category>
		<category><![CDATA[meta-blogging]]></category>

		<guid isPermaLink="false">http://blog.nonken.net/?p=10</guid>
		<description><![CDATA[I think that should be enough for now.
The advice I got online suggested that for a professional blog, which I intend this to be, I should run my own (or pay for individual service), rather than depend on something like Blogspot. Wordpress seems to be the blogging software of choice.
My hosting service gives me full [...]]]></description>
			<content:encoded><![CDATA[<p>I think that should be enough for now.</p>
<p>The advice I got online suggested that for a professional blog, which I intend this to be, I should run my own (or pay for individual service), rather than depend on something like Blogspot. Wordpress seems to be the blogging software of choice.</p>
<p>My hosting service gives me full root access so setting it up was just a matter of following instructions. I did have to install MySQL, which fortunately is automated, and I threw in phpmyadmin as well. The rest was digging up some information I&#8217;d already learned to do some redirection. Any of the following URLs will work:</p>
<ul>
<li>blog.nonken.net</li>
<li>bmb.nonken.net</li>
<li>baremetal.nonken.net</li>
<li>baremetalblog.nonken.net (default)</li>
<li>www.nonken.net/blog</li>
</ul>
<p>They all redirect except the last two. Eventually I may play with the appearance but for now this works.</p>
<p>My biggest complaint is the slow response to typing. It looks like every character has to do a round trip, and backspace is particularly bad. What&#8217;s worse is that backspace <em>needs</em> to be fast; it&#8217;s way too easy to overrun far past where you intended. On any other editor I can use the keyboard&#8217;s built-in auto-repeat and take my cues visually.</p>
<p>I hereby invoke the Principle of Least Astonishment. It doesn&#8217;t work as I expect and I don&#8217;t like it. I can tolerate it for now but it could be a deal-breaker; it might be enough by itself to make me try other blogging software. (It looks like it&#8217;s a function of my connection. Unfortunately I share this connection with at least six other people, and it&#8217;s the cheapest one I can get. This means that the software depends on you having a fast, reliable connection all the time. Still not good.)</p>
<p>In the meantime the temptation is to start blogging <em>immediately</em>. I have to restrain myself; I&#8217;ve spent several hours getting to this point, it&#8217;s not going to end up with a full set of insightful postings overnight. Time to relax and find something else to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=10</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://baremetalblog.nonken.net/?p=1</link>
		<comments>http://baremetalblog.nonken.net/?p=1#comments</comments>
		<pubDate>Mon, 07 Sep 2009 21:54:23 +0000</pubDate>
		<dc:creator>Jeffrey Nonken</dc:creator>
				<category><![CDATA[Meta-blogging]]></category>

		<guid isPermaLink="false">http://www.nonken.net/blog/?p=1</guid>
		<description><![CDATA[Ah, the first entry. No content yet. The blog has yet to take shape. Who knows how it might end up?
]]></description>
			<content:encoded><![CDATA[<p>Ah, the first entry. No content yet. The blog has yet to take shape. Who knows how it might end up?</p>
]]></content:encoded>
			<wfw:commentRss>http://baremetalblog.nonken.net/?feed=rss2&amp;p=1</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
