Comparing strings (Instructions)
Yesterday we ended here:
# 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
Now we convert the remaining instructions to assembly-like pseudo code:
# A, B: strings to compare (pointer)
# same?: flag that stores equalness
LDI same?, 1
LD n, *(A)
INC 1
while:
BZ n, done
CMP same?, *(A), *(B)
BNZ same?, done
INC A
INC B
DEC n
JMP while
done:
# same? has now the right value
I might rewrite this after thinking about what kind of conditionals and comparison function I would like to have for my fantasy machine.