| 1 |
|
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"strconv" |
| 7 |
|
| 8 |
. "github.com/mmcloughlin/avo/build" |
| 9 |
. "github.com/mmcloughlin/avo/operand" |
| 10 |
. "github.com/mmcloughlin/avo/reg" |
| 11 |
) |
| 12 |
|
| 13 |
func main() { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
const n = 19 |
| 18 |
|
| 19 |
TEXT("GP8", NOSPLIT, "func() uint8") |
| 20 |
Doc("GP8 returns the sum 1+2+...+" + strconv.Itoa(n) + " using " + strconv.Itoa(n) + " distinct 8-bit registers.") |
| 21 |
|
| 22 |
|
| 23 |
x := make([]Register, n) |
| 24 |
i := 0 |
| 25 |
|
| 26 |
|
| 27 |
for ; i < 15; i++ { |
| 28 |
x[i] = GP8L() |
| 29 |
MOVB(U8(i+1), x[i]) |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
for ; i < n; i++ { |
| 34 |
x[i] = GP8H() |
| 35 |
MOVB(U8(i+1), x[i]) |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
for i := 1; i < n; i++ { |
| 40 |
ADDB(x[i], x[0]) |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
Store(x[0], ReturnIndex(0)) |
| 45 |
RET() |
| 46 |
|
| 47 |
Generate() |
| 48 |
} |