From 4eea879cdb354382fa577719ecb93ac25570560b Mon Sep 17 00:00:00 2001 From: sejo Date: Wed, 7 Jul 2021 16:08:55 -0500 Subject: [PATCH] little person computer program --- src/little_person_computer.gmo | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/little_person_computer.gmo b/src/little_person_computer.gmo index fdc3c6a..5dcbef7 100644 --- a/src/little_person_computer.gmo +++ b/src/little_person_computer.gmo @@ -8,6 +8,68 @@ is uses the decimal system, with words of three-digits each. it has ten instructions and 100 memory addresses. +# example programs + +written in the corresponding assembly language. + +as part of the {s-camino} practice. + +## multiplication of two numbers + +### no labels + +pure assembler version, no labels. + +* 15 is the address for the result +* 16 is the address for 'a' +* 17 is the addres for 'b' + +``` + INP + STA 16 + INP + STA 17 + BRZ 11 + LDA 16 + ADD 15 + STA 15 + LDA 17 + SUB 14 + BRA 3 + LDA 15 + OUT + HLT + DAT 1 + DAT 0 + DAT 0 + DAT 0 +``` + +### with labels + +the same behavior as above, but using labels for easier programming and reading + +``` +inputs INP + STA a + INP +loop STA b + BRZ print // finish if b is 0 + LDA a + ADD result + STA result + LDA b + SUB one + BRA loop +print LDA result + OUT + HLT +one DAT 1 +result DAT 0 +a DAT 0 +b DAT 0 +``` + # external links => https://teachcomputerscience.com/little-man-computer/ little man computer