Comparing strings, destructured
We need to convert our implementation to something close to machine code. For that, we translate the while-statement (a staple of structured programming) into a conditional jump instruction.
From this:
# 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
to this:
# A, B: strings to compare (pointer)
# same?: flag that stores equalness
same? := True
n := *(A) + 1
while:
if n==0: goto done
if *(A) <> *(B):
same? := False
goto done
A++, B++, n--
goto while
done:
# same? has now the right value