math.bitwise: Fix example for bitfield*

master
Doug Coleman 2020-06-12 19:34:25 -05:00
parent a7b058bed1
commit e9ab963df9
1 changed files with 19 additions and 15 deletions

View File

@ -11,7 +11,8 @@ HELP: bitfield
{ { $snippet "shift" } " - the top of the stack is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" } { { $snippet "shift" } " - the top of the stack is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" }
{ { $snippet "{ constant shift }" } " - " { $snippet "constant" } " is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" } { { $snippet "{ constant shift }" } " - " { $snippet "constant" } " is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" }
} }
"The bit field specifier is processed left to right, so stack values should be supplied in reverse order." } "The last entry in the bit field specifier is processed in reverse, so stack values are supplied in reverse order, e.g. the leftmost stack value is the last bit field specifier."
}
{ $examples { $examples
"Consider the following specification:" "Consider the following specification:"
{ $list { $list
@ -56,7 +57,8 @@ HELP: bitfield*
{ { $snippet "shift" } " - the top of the stack is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" } { { $snippet "shift" } " - the top of the stack is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" }
{ { $snippet "{ constant shift }" } " - " { $snippet "constant" } " is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" } { { $snippet "{ constant shift }" } " - " { $snippet "constant" } " is shifted to the left by " { $snippet "shift" } " bits and bitor'd with the bit field" }
} }
"The bit field specifier is processed left to right, so stack values should be supplied in reverse order." } "The bit field specifier is processed in order, so stack values are taken from left to right."
}
{ $examples { $examples
"Consider the following specification:" "Consider the following specification:"
{ $list { $list
@ -80,19 +82,21 @@ HELP: bitfield*
"1 2 3 baz-bitfield* ." "1 2 3 baz-bitfield* ."
"233473" "233473"
} }
"Square the 3 from the stack and shift 8, place the 1 from the stack at bit 5, and shift a constant 1 to bit 2:" "Put a 1 at bit 1, put the 1 from the stack at bit 5, square the 3 and put it at bit 8:"
{ $example { $example
"USING: math math.bitwise prettyprint ;" "USING: math math.bitwise prettyprint ;"
"1 3" "1 3"
" {" " {"
" { sq 8 }"
" 5"
" { 1 2 }" " { 1 2 }"
" } bitfield .b" " 5"
" { sq 8 }"
" } bitfield* .b"
"0b100100100100" "0b100100100100"
} }
} ; } ;
{ bitfield bitfield* } related-words
HELP: bits HELP: bits
{ $values { "m" integer } { "n" integer } { "m'" integer } } { $values { "m" integer } { "n" integer } { "m'" integer } }
{ $description "Keep only " { $snippet "n" } " bits from the integer " { $snippet "m" } ". For negative numbers, represent the number as two's complement (a positive integer representing a negative integer)." } { $description "Keep only " { $snippet "n" } " bits from the integer " { $snippet "m" } ". For negative numbers, represent the number as two's complement (a positive integer representing a negative integer)." }