cpct_set2Bits

Sets the value of a selected group of 2 bits into a bitarray to [0-3]

C Definition

void cpct_set2Bits (void* array, u16 value, u16 index)

Input Parameters (6 Bytes, B register ignored, only C register is used for value)

(2B DE) arrayPointer to the first byte of the array
(2B HL) indexPosition of the group of 2 bits in the array to be modified
(2B BC) valueNew value {0, 1, 2, 3} for the group of 2 bits at the given position.  If you call from assembly, you can safely ignore B register and set only C register.

Assembly call (Input parameters on registers)

call cpct_set2Bits_asm

Parameter Restrictions

  • array must be the memory location of the first byte of the array.  However, this function will accept any given 16-value, without performing any check.  Giving and incorrect array pointer will have unpredictable results: a random group of 2 bits from your memory may result changed.
  • value new value for the selected group of 2 bits [0-3].  Only the 2 Least Significant Bits (LSBs) are used.  This means that any given value will “work”: value module 4 will be finally inserted in the array position (index).
  • index position of the group of 2 bits to be modified in the array, starting in 0.  Again, as this function does not perform any boundary check, if you gave an index outside the boundaries of the array, a group of 2 bits outside the array will be changed in memory, what will have unpredictable results.

Known limitations

  • Maximum of 65536 bits, 16384 bytes per array.

Details

Set the new value of the 2-bits group at the given position (index) in the specified array.  This function assumes that the array elements have a size of 8 bits and also that the given index is not bigger than the number of 2-bits groups in the array (size of the array multiplied by 4).  The value to be set is also assumed to be in the range [0-3] but other values will “work” (just the 2 Least Significant Bits will be used, so value module 4 will be inserted).

Destroyed Register values

AF, BC, DE, HL

Required memory

C-bindings57 bytes
ASM-bindings53 bytes

Time Measures

Case       | microSecs(us) | CPU Cycles
-----------------------------------------
Best  (0)  |       55      |    220
-----------------------------------------
2nd   (3)  |       57      |    228
-----------------------------------------
3rd   (1)  |       59      |    236
-----------------------------------------
Worst (2)  |       61      |    244
-----------------------------------------
Asm saving |      -15      |    -60
-----------------------------------------
Sets the value of a selected group of 2 bits into a bitarray to [0-3]
unsigned int (u16 = unsigned 16-bits, 2 bytes)
Close