Fixed bug where comments were not properly ignored
This commit is contained in:
parent
d648660889
commit
2a53da6f95
@ -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
|
||||
|
BIN
examples/hellorld
Normal file
BIN
examples/hellorld
Normal file
Binary file not shown.
@ -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
|
||||
|
@ -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
|
||||
|
11
masm/main.go
11
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] == ',' {
|
||||
|
Loading…
Reference in New Issue
Block a user