Do not put variables after code

Apparently the original assembler does not do this, and putting
them inline with the code is needed for subroutines
This commit is contained in:
Sasha Koshka 2022-10-27 17:37:25 -04:00
parent 86b642ba25
commit d648660889
2 changed files with 3 additions and 8 deletions

View File

@ -81,6 +81,7 @@ func (machine *Machine) Execute (offset int16) (err error) {
// Store the PC at address X and jump to X+1 // Store the PC at address X and jump to X+1
machine.memory[operand] = machine.counter machine.memory[operand] = machine.counter
machine.counter = operand machine.counter = operand
println(operand)
case LOAD: case LOAD:
// Load contents of address X into AC // Load contents of address X into AC

View File

@ -65,8 +65,7 @@ func main () {
origin := 0 origin := 0
originSet := false originSet := false
operations := []Statement { } statements := []Statement { }
symbols := []Statement { }
symbolTable := map[string] int { } symbolTable := map[string] int { }
// parse // parse
@ -87,11 +86,7 @@ func main () {
} }
if statement.opcode != ORG { if statement.opcode != ORG {
if statement.isOperation { statements = append(statements, statement)
operations = append(operations, statement)
} else {
symbols = append(symbols, statement)
}
} }
if err != nil { if err != nil {
@ -105,7 +100,6 @@ func main () {
// get symbol addresses // get symbol addresses
placer := origin placer := origin
statements := append(operations, symbols...)
for _, statement := range statements { for _, statement := range statements {
if statement.label != "" { if statement.label != "" {
_, alreadyDefined := symbolTable[statement.label] _, alreadyDefined := symbolTable[statement.label]