| 1 | # data |
| 2 | |
| 3 | Constructing data sections in `avo`. |
| 4 | |
| 5 | A data section is declared with the `GLOBL` function, and values are specified with `DATA`. The size of the data section will grow as values are added to it. |
| 6 | |
| 7 | [embedmd]:# (asm.go go /.*GLOBL\(/ /^$/) |
| 8 | ```go |
| 9 | bytes := GLOBL("bytes", RODATA|NOPTR) |
| 10 | DATA(0, U64(0x0011223344556677)) |
| 11 | DATA(8, String("strconst")) |
| 12 | DATA(16, F32(math.Pi)) |
| 13 | DATA(24, F64(math.Pi)) |
| 14 | DATA(32, U32(0x00112233)) |
| 15 | DATA(36, U16(0x4455)) |
| 16 | DATA(38, U8(0x66)) |
| 17 | DATA(39, U8(0x77)) |
| 18 | ``` |
| 19 | |
| 20 | The `GLOBL` function returns a reference which may be used in assembly code. The following function indexes into the data section just created. |
| 21 | |
| 22 | [embedmd]:# (asm.go go /.*TEXT.*DataAt/ /RET.*/) |
| 23 | ```go |
| 24 | TEXT("DataAt", NOSPLIT, "func(i int) byte") |
| 25 | Doc("DataAt returns byte i in the 'bytes' global data section.") |
| 26 | i := Load(Param("i"), GP64()) |
| 27 | ptr := Mem{Base: GP64()} |
| 28 | LEAQ(bytes, ptr.Base) |
| 29 | b := GP8() |
| 30 | MOVB(ptr.Idx(i, 1), b) |
| 31 | Store(b, ReturnIndex(0)) |
| 32 | RET() |
| 33 | ``` |