Files
avo/examples/sum/asm.go
2019-01-04 18:23:44 -08:00

29 lines
562 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, operand.Imm(0))
JE(operand.LabelRef("done"))
ADDQ(operand.Mem{Base: ptr}, s)
ADDQ(operand.Imm(8), ptr)
DECQ(n)
JMP(operand.LabelRef("loop"))
LABEL("done")
Store(s, ReturnIndex(0))
RET()
Generate()
}