User manual
586
mikoPascal PRO for PIC32
MikroElektronika
memchr
memcmp
Prototype
function memchr(p : ^byte; ch : byte; n : word) : word;
Description The function locates the rst occurrence of the word ch in the initial n words of memory area starting
at the address p. The function returns the offset of this occurrence from the memory address p or
0xFFFF if ch was not found.
For the parameter p you can use either a numerical value (literal/variable/constant) indicating memory
address or a dereferenced value of an object, for example @mystring or @PORTB.
Example
txt := ‘mikroElektronika’;
res := memchr(@txt, ‘e’, 16); // example locates rst occurrence of the
letter ‘e’ in the string ‘txt’ in the rst 16 characters of the string
Prototype
function memcmp(p1, p2 : ^byte; n : word) : integer;
Description The function returns a positive, negative, or zero value indicating the relationship of rst n words of
memory areas starting at addresses p1 and p2.
This function compares two memory areas starting at addresses p1 and p2 for n words and returns a
value indicating their relationship as follows:
Value Meaning
< 0 p1 “less than” p2
= 0 p1 “equal to” p2
> 0 p1 “greater than” p2
The value returned by the function is determined by the difference between the values of the rst pair
of words that differ in the strings being compared.
For parameters p1 and p2 you can use either a numerical value (literal/variable/constant) indicating
memory address or a dereferenced value of an object, for example @mystring or @PORTB.
Example
txt := ‘mikroElektronika’;
txt_sub := ‘mikro’;
res := memcmp(@txt, @txt_sub, 16); // returns 69, which is ASCII code of
the rst differing character - letter ‘E’