cpct_set4Bits

Sets the value of a selected group of 4 bits (nibble) into a bitarray to [0-15]

C Definition

void cpct_set4Bits (void* array, u16 index, u8 value)

Input Parameters (4 Bytes)

(2B DE) arrayPointer to the first byte of the array
(2B HL) indexPosition of the group of 4 bits in the array to be modified
(1B C ) valueNew value [0-15] for the group of 4 bits at the given position

Assembly call (Input parameters on registers)

call cpct_set4Bits_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 nibble from your memory may result changed.
  • index position of the group of 4 bits (nibble) 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 nibble outside the array will be changed in memory, what will have unpredictable results.
  • value new value for the selected nibble [0-15].  Only the 4 Least Significant Bits (LSBs) are used.  This means that any given value will “work”: value module 16 will be finally inserted in the array position (index).

Known limitations

  • Maximum of 65536 bits, 32768 bytes per array.

Details

Set the new value of the 4-bits group (nibble) 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 nibbles in the array (size of the array multiplied by 2).  The value to be set is also assumed to be in the range [0-15] but other values will “work” (just the 4 Least Significant Bits will be used, so value module 16 will be inserted).

Destroyed Register values

AF, BC, DE, HL

Required memory

33 bytes

Time Measures

Case       | Cycles | microSecs (us)
-------------------------------
Best  (1)  |   175  |  43.75
-------------------------------
Worst (0)  |   198  |  49.50
-------------------------------
Asm saving |   -84  | -21.00
-------------------------------
Sets the value of a selected group of 4 bits (nibble) into a bitarray to [0-15]
unsigned int (u16 = unsigned 16-bits, 2 bytes)
unsigned char (u8 = unsigned 8-bits, 1 byte )
Close