Comparing strings
For our search routine we need to compare strings. A string is represented as a sequence of bytes[^In our very special machine we could actually save a full string in a memory cell, but let‘s ignore this for the time being.]. The first byte is the length of the string, followed by the individual characters.
To compare two strings we start by comparing their lengths. If it is the same we compare each character one by one until we have found a pair that is different. Otherwise we know it is equal.
# A, B: strings to compare (pointer)
# same?: flag that stores equalness
same? := True
n := *(A) + 1
while n > 0:
if *(A) <> *(B):
same? := False
break
A++, B++, n--
# same? has now the right value