diff --git a/core/asm/compiler.go b/core/asm/compiler.go index c951725213..00da650913 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -57,6 +57,7 @@ func NewCompiler(debug bool) *Compiler { // second stage to push labels and determine the right // position. func (c *Compiler) Feed(ch <-chan token) { + var prev token for i := range ch { switch i.typ { case number: @@ -73,10 +74,14 @@ func (c *Compiler) Feed(ch <-chan token) { c.labels[i.text] = c.pc c.pc++ case label: - c.pc += 5 + c.pc += 4 + if prev.typ == element && isJump(prev.text) { + c.pc++ + } } c.tokens = append(c.tokens, i) + prev = i } if c.debug { fmt.Fprintln(os.Stderr, "found", len(c.labels), "labels") diff --git a/core/asm/compiler_test.go b/core/asm/compiler_test.go index 065e1961df..684ca574b0 100644 --- a/core/asm/compiler_test.go +++ b/core/asm/compiler_test.go @@ -32,6 +32,13 @@ func TestCompiler(t *testing.T) { `, output: "5a5b6300000001", }, + { + input: ` + PUSH @label + label: +`, + output: "63000000055b", + }, } for _, test := range tests { ch := Lex([]byte(test.input), false)