cpct_get4Bits

Returns the value of a given group of 4 bits into an array ( [0-15] )

C Definition

u8 cpct_get4Bits (void* array, u16 index);

Input Parameters (4 Bytes)

(2B DE) arrayPointer to the first byte of the array
(2B HL) indexPosition of the group of 4 bits to be retrieved from the array

Assembly call (Input parameters on registers)

call cpct_get4Bits_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.  So, be warned that giving mistaken values to this function will not make it fail, but giving an unpredictable return result.
  • index position of the group of 4 bits to be retrieved from the array, starting in 0.  As this function does not perform any boundary check, if you gave an index outside the boundaries of the array, the return result would be unpredictable and meaningless.

Return value

u8Value of the selected group of 4 bits: [0-15]

Known limitations

  • Maximum of 65536 groups of 4-bits, 32768 bytes per array.

Details

Returns a value from 0 to 15 depending on the value of the 4-bits group at the given position (index) in the specified array.  It will assume that the array elements have a size of 8 bits and also that the given position is not bigger than the number of bits in the array (size of the array multiplied by 2).

Destroyed Register values

AF, BC, DE, HL

Required memory

C-bindings25 bytes
ASM-bindings22 bytes

Time Measures

Case      | microSecs (us) | CPU Cycles |
-----------------------------------------
Best (1)  |      30        |     120    |
-----------------------------------------
Worst (0) |      33        |     132    |
-----------------------------------------
ASM Saving|     -12        |     -48    |
-----------------------------------------

We need to know how many bytes do we have to jump into the array, to move HL to that point.  We advance 1 byte for each 2 index positions (8 bits) So, first, we calculate INDEX/2 (HL/2) to know the target byte, and the remainder to know the group of 4bits we want [ 0000 1111 ], and that will go to the Carry Flag.

unsigned char (u8 = unsigned 8-bits, 1 byte )
Returns the value of a given group of 4 bits into an array ( [0-15] )
unsigned int (u16 = unsigned 16-bits, 2 bytes)
Close