Fixed an incorrect register move
This commit is contained in:
parent
8766a4ef1a
commit
08d5f38072
2 changed files with 7 additions and 1 deletions
|
@ -2,8 +2,10 @@ import log
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
x := 12
|
collatz(12)
|
||||||
|
}
|
||||||
|
|
||||||
|
collatz(x) {
|
||||||
loop {
|
loop {
|
||||||
if x & 1 == 0 {
|
if x & 1 == 0 {
|
||||||
x /= 2
|
x /= 2
|
||||||
|
|
|
@ -9,6 +9,10 @@ import (
|
||||||
|
|
||||||
// CompileLoop compiles a loop instruction.
|
// CompileLoop compiles a loop instruction.
|
||||||
func (f *Function) CompileLoop(loop *ast.Loop) error {
|
func (f *Function) CompileLoop(loop *ast.Loop) error {
|
||||||
|
for _, register := range f.CPU.Input {
|
||||||
|
f.SaveRegister(register)
|
||||||
|
}
|
||||||
|
|
||||||
f.count.loop++
|
f.count.loop++
|
||||||
label := fmt.Sprintf("%s_loop_%d", f.UniqueName, f.count.loop)
|
label := fmt.Sprintf("%s_loop_%d", f.UniqueName, f.count.loop)
|
||||||
f.AddLabel(label)
|
f.AddLabel(label)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue