From 2a53da6f95ff756136bd579385a2ccab613cef22 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 27 Oct 2022 22:51:04 -0400 Subject: [PATCH] Fixed bug where comments were not properly ignored --- examples/greet.mas | 76 +++++++++++++++++++++--------------------- examples/hellorld | Bin 0 -> 42 bytes examples/hellorld.mas | 24 ++++++------- marcie.go | 1 - masm/main.go | 11 +++--- 5 files changed, 55 insertions(+), 57 deletions(-) create mode 100644 examples/hellorld diff --git a/examples/greet.mas b/examples/greet.mas index 06f6499..fdbfd73 100644 --- a/examples/greet.mas +++ b/examples/greet.mas @@ -1,43 +1,5 @@ org 100 -one, hex 1 -newline, hex 0A -exclamation, chr ! - -questionCounter, adr question -question, chr W - chr h - chr a - chr t - hex 20 - chr i - chr s - hex 20 - chr y - chr o - chr u - chr r - hex 20 - chr n - chr a - chr m - chr e - chr ? - hex 0A - hex 00 - -greetingCounter, adr greeting -greeting, chr H - chr e - chr l - chr l - chr o - chr , - hex 20 - hex 00 - -responseCounter, hex 0 - // ask the user their name askLoopStart, loadi questionCounter skipcond 800 @@ -89,3 +51,41 @@ responseCounter, hex 0 playbackLoopEnd, clear halt + +one, hex 1 +newline, hex 0A +exclamation, chr ! + +questionCounter, adr question +question, chr W + chr h + chr a + chr t + hex 20 + chr i + chr s + hex 20 + chr y + chr o + chr u + chr r + hex 20 + chr n + chr a + chr m + chr e + chr ? + hex 0A + hex 00 + +greetingCounter, adr greeting +greeting, chr H + chr e + chr l + chr l + chr o + chr , + hex 20 + hex 00 + +responseCounter, hex 0 diff --git a/examples/hellorld b/examples/hellorld new file mode 100644 index 0000000000000000000000000000000000000000..0d221d6bef3c454f33ab90718adaf216683e3963 GIT binary patch literal 42 tcmZQzxWLiDP{5GDAi!b3slYLTfq{#Gks*U2l_3WR^BIbOWC~D>0RWgR2BiQ1 literal 0 HcmV?d00001 diff --git a/examples/hellorld.mas b/examples/hellorld.mas index 4be5998..c403b69 100644 --- a/examples/hellorld.mas +++ b/examples/hellorld.mas @@ -1,3 +1,15 @@ +// if the current character is zero, halt +loopStart, loadi counter +skipcond 800 + halt + +// otherwise, output it, increment, and loop +output +load counter +add one +store counter +jump loopStart + counter, adr string one, dec 1 @@ -11,15 +23,3 @@ string, chr h chr d hex a hex 0 - -// if the current character is zero, halt -loopStart, loadi counter -skipcond 800 - halt - -// otherwise, output it, increment, and loop -output -load counter -add one -store counter -jump loopStart diff --git a/marcie.go b/marcie.go index 2698f6a..4a177a8 100644 --- a/marcie.go +++ b/marcie.go @@ -81,7 +81,6 @@ func (machine *Machine) Execute (offset int16) (err error) { // Store the PC at address X and jump to X+1 machine.memory[operand] = machine.counter machine.counter = operand - println(operand) case LOAD: // Load contents of address X into AC diff --git a/masm/main.go b/masm/main.go index 60adc44..1e09fca 100644 --- a/masm/main.go +++ b/masm/main.go @@ -72,6 +72,10 @@ func main () { for lineNumber := 0; inputScanner.Scan(); lineNumber ++ { tokens := strings.Fields(inputScanner.Text()) if len(tokens) == 0 { continue } + if tokens[0][0] == '/' { + // skip line if it is a comment + continue + } statement, err := parseStatement(tokens) statement.lineNumber = lineNumber @@ -128,7 +132,7 @@ func main () { // for _, statement := range statements { // fmt.Println(statement) // } -// + // for symbol, address := range symbolTable { // fmt.Println(symbol, address) // } @@ -195,11 +199,6 @@ func main () { } func parseStatement (tokens []string) (statement Statement, err error) { - if tokens[0][0] == '/' { - // skip line if it is a comment - return - } - // get label if it exists possibleLabel := tokens[0] if possibleLabel[len(possibleLabel) - 1] == ',' {