Files
avo/examples/sum/asm.go
Michael McLoughlin 602bb5197c build: unify Label function signatures
The Context.Label method and LABEL global function did not agree. Also
breaks the convention I'd like to set that capitalized functions must
agree with existing Go assembly syntax.

To help avoid a conflict with `avo.Label`, attributes were moved to
their own package.

Fixes #35
2019-01-05 18:18:49 -08:00

29 lines
524 B
Go

// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
)
func main() {
TEXT("Sum", "func(xs []uint64) uint64")
Doc("Sum returns the sum of the elements in xs.")
ptr := Load(Param("xs").Base(), GP64())
n := Load(Param("xs").Len(), GP64())
s := GP64()
XORQ(s, s)
Label("loop")
CMPQ(n, Imm(0))
JE(LabelRef("done"))
ADDQ(Mem{Base: ptr}, s)
ADDQ(Imm(8), ptr)
DECQ(n)
JMP(LabelRef("loop"))
Label("done")
Store(s, ReturnIndex(0))
RET()
Generate()
}