Skip to content

Instantly share code, notes, and snippets.

@mmcloughlin
Last active December 24, 2018 22:42
Show Gist options
  • Select an option

  • Save mmcloughlin/340d530e3c97afbf71a6e1acdc0945fa to your computer and use it in GitHub Desktop.

Select an option

Save mmcloughlin/340d530e3c97afbf71a6e1acdc0945fa to your computer and use it in GitHub Desktop.
#include "textflag.h"
DATA b<>+0(SB)/8, $0x0011223344556677
DATA b<>+8(SB)/8, $"strconst"
DATA b<>+16(SB)/8, $3.141592
DATA b<>+24(SB)/4, $3.141592
// 28-31: empty
DATA b<>+32(SB)/4, $0x00112233
DATA b<>+36(SB)/2, $0x4455
DATA b<>+38(SB)/1, $0x66
DATA b<>+39(SB)/1, $0x77
// 40-42: empty
DATA b<>+43(SB)/4, $"hey"
// 47: empty
GLOBL b<>(SB), RODATA, $48
TEXT ·DataAt(SB),0,$0-9
MOVQ i+0(FP), AX
LEAQ b<>+0x00(SB), BX
MOVB 0(BX)(AX*1), CL
MOVB CL, ret+8(FP)
RET
package main
import (
"encoding/hex"
"fmt"
)
const Size = 48
func DataAt(i int) byte
func ReadDataSection() []byte {
b := make([]byte, Size)
for i := 0; i < Size; i++ {
b[i] = DataAt(i)
}
return b
}
func main() {
b := ReadDataSection()
fmt.Print(hex.Dump(b))
}
00000000 77 66 55 44 33 22 11 00 73 74 72 63 6f 6e 73 74 |wfUD3"..strconst|
00000010 7a 00 8b fc fa 21 09 40 d8 0f 49 40 00 00 00 00 |z....!.@..I@....|
00000020 33 22 11 00 55 44 66 77 00 00 00 68 65 79 00 00 |3"..UDfw...hey..|
@mmcloughlin
Copy link
Author

Experiment with DATA sections in Go assembly. Confirms that:

  • Data types and sizes can be mixed.
  • Not all bytes have to be specified. Unspecified bytes are zero in this case, but I am not sure that's specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment