Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
38
02-01.md
38
02-01.md
|
|
@ -45,14 +45,16 @@ bytes.) I examined the subroutine line by line, saving a cycle here and
|
|||
a cycle there, until the code truly seemed to be optimized. When I was
|
||||
done, the key part of the code looked something like this:
|
||||
|
||||
LoopTop:
|
||||
lodsb ;get the next byte to extract a bit from
|
||||
and al,ah ;isolate the bit we want
|
||||
rol al,cl ;rotate the bit into the desired position
|
||||
or bl,al ;insert the bit into the final nibble
|
||||
dec cx ;the next bit goes 1 place to the right
|
||||
dec dx ;count down the number of bits
|
||||
jnz LoopTop ;process the next bit, if any
|
||||
```nasm
|
||||
LoopTop:
|
||||
lodsb ;get the next byte to extract a bit from
|
||||
and al,ah ;isolate the bit we want
|
||||
rol al,cl ;rotate the bit into the desired position
|
||||
or bl,al ;insert the bit into the final nibble
|
||||
dec cx ;the next bit goes 1 place to the right
|
||||
dec dx ;count down the number of bits
|
||||
jnz LoopTop ;process the next bit, if any
|
||||
```
|
||||
|
||||
Now, it's hard to write code that's much faster than seven instructions,
|
||||
only one of which accesses memory, and most programmers would have
|
||||
|
|
@ -68,15 +70,17 @@ total of four separate time-consuming multibit rotations!
|
|||
|
||||
I changed the code to the following:
|
||||
|
||||
LoopTop:
|
||||
lodsb ;get the next byte to extract a bit from
|
||||
and al,ah ;isolate the bit we want
|
||||
or bl,al ;insert the bit into the final nibble
|
||||
rol bl,1 ;make room for the next bit
|
||||
dec dx ;count down the number of bits
|
||||
jnz LoopTop ;process the next bit, if any
|
||||
rol bl,cl ;rotate all four bits into their final
|
||||
; positions at the same time
|
||||
```nasm
|
||||
LoopTop:
|
||||
lodsb ;get the next byte to extract a bit from
|
||||
and al,ah ;isolate the bit we want
|
||||
or bl,al ;insert the bit into the final nibble
|
||||
rol bl,1 ;make room for the next bit
|
||||
dec dx ;count down the number of bits
|
||||
jnz LoopTop ;process the next bit, if any
|
||||
rol bl,cl ;rotate all four bits into their final
|
||||
; positions at the same time
|
||||
```
|
||||
|
||||
This moved the costly multibit rotation out of the loop so that it was
|
||||
performed just once, rather than four times. While the code may not look
|
||||
|
|
|
|||
Loading…
Reference in a new issue