diff --git a/src/assembly.go b/src/assembly.go index 52ad43a..ce7d730 100644 --- a/src/assembly.go +++ b/src/assembly.go @@ -128,7 +128,11 @@ func Assembly(code []*Command, file string, stackSize int) (string, error) { program += fmt.Sprintf("subq %%rax, %d(%%r12)", -8 * m.Offset) + br } } - program += "movq $0, (%r12)" + br + if c.Offset != 0 { + program += fmt.Sprintf("movq $0, %d(%%r12)", -8 * c.Offset) + br + } else { + program += "movq $0, (%r12)" + br + } } break } diff --git a/src/optimize.go b/src/optimize.go index 34efe48..1022731 100644 --- a/src/optimize.go +++ b/src/optimize.go @@ -107,7 +107,7 @@ func optimizePointerMovement(commands []*Command, verbose bool) []*Command { i := 0 block := []*Command{} for i < len(commands) { - if strings.Contains("><+-,.", commands[i].String) && i < len(commands) - 1 { + if (strings.Contains("><+-,.", commands[i].String) || commands[i].String == "[-]") && i < len(commands) - 1 { block = append(block, commands[i]) } else { if len(block) > 0 { @@ -216,6 +216,7 @@ func getRemoteCommands(commands []*Command) []*Command { Offset: pointer, Row: c.Row, Col: c.Col, + MultiplyLoop: c.MultiplyLoop, }) } }