Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
24
16-07.md
24
16-07.md
|
|
@ -119,17 +119,17 @@ implemented code that sprang from that new perspective.
|
|||
|
||||
You can see one example of this in Listing 16.6, where Willem uses **CMP
|
||||
AX,0101H** to check two bytes at once. While you might think of this as
|
||||
nothing more than a doubling up of tests, it’s a little more than that,
|
||||
nothing more than a doubling up of tests, it's a little more than that,
|
||||
especially when taken together with the use of two loops. This is a
|
||||
break with the serial nature of the C code, a recognition that word
|
||||
counting is really nothing more than a state machine that transitions
|
||||
from the “in word” state to the “not in word” state and back, counting a
|
||||
from the "in word" state to the "not in word" state and back, counting a
|
||||
word on one but not both of those transitions. Willem says, in effect,
|
||||
“We’re in a word; if the next two bytes are non-separators, then we’re
|
||||
still in a word, else we’re not in a word, so count and change to the
|
||||
appropriate state.” That’s really quite different from saying, as I
|
||||
originally did, “If the last byte was a non-separator, then if the
|
||||
current byte is a separator, then count a word.” Willem has moved away
|
||||
"We're in a word; if the next two bytes are non-separators, then we're
|
||||
still in a word, else we're not in a word, so count and change to the
|
||||
appropriate state." That's really quite different from saying, as I
|
||||
originally did, "If the last byte was a non-separator, then if the
|
||||
current byte is a separator, then count a word." Willem has moved away
|
||||
from the all-in-one approach, splitting the code up into state-specific
|
||||
chunks that are more efficient because each does only the work required
|
||||
in a particular state.
|
||||
|
|
@ -140,27 +140,27 @@ the word), rather than waiting for a separator following a non-separator
|
|||
(at the end of the word). My friend Dan Illowsky describes the thought
|
||||
process leading to this approach thusly:
|
||||
|
||||
*“I try to code as closely as possible to the real world nature of those
|
||||
*"I try to code as closely as possible to the real world nature of those
|
||||
things my program models. It seems somehow wrong to me to count the end
|
||||
of a word as you do when you look for a transition from a word to a
|
||||
non-word. A word is not a transition, it is the presence of a group of
|
||||
characters. Thought of this way, the code would have counted the word
|
||||
when it first detected the group. Had you done this, your main program
|
||||
would not have needed to look for the possible last transition or deal
|
||||
with the semantics of the value in **CharValue**.”*
|
||||
with the semantics of the value in **CharValue**."*
|
||||
|
||||
John Richardson, of New York, contributed a good example of the benefits
|
||||
of a different perspective (in this case, a hardware perspective). John
|
||||
eliminated all branches used for detecting word edges; the inner loop of
|
||||
his code is shown in Listing 16.7. As John explains it:
|
||||
|
||||
*“My next shot was to get rid of all the branches in the loop. To do
|
||||
*"My next shot was to get rid of all the branches in the loop. To do
|
||||
that, I reached back to my college hardware courses. I noticed that we
|
||||
were really looking at an edge triggered device we want to count each
|
||||
time the I’m a character state goes from one to zero. Remembering that
|
||||
time the I'm a character state goes from one to zero. Remembering that
|
||||
XOR on two single-bit values will always return whether the bits are
|
||||
different or the same, I implemented a transition counter. The counter
|
||||
triggers every time a word begins or ends.”*
|
||||
triggers every time a word begins or ends."*
|
||||
|
||||
------------------------ --------------------------------- --------------------
|
||||
[Previous](16-06.html) [Table of Contents](index.html) [Next](16-08.html)
|
||||
|
|
|
|||
Loading…
Reference in a new issue