github.com/chenzhuoyu/iasm@v0.9.1/x86_64/program_test.go (about) 1 package x86_64 2 3 import ( 4 `bytes` 5 `testing` 6 7 `github.com/chenzhuoyu/iasm/expr` 8 `github.com/davecgh/go-spew/spew` 9 ) 10 11 func TestProgram_Assemble(t *testing.T) { 12 a := CreateArch() 13 b := CreateLabel("bak") 14 s := CreateLabel("tab") 15 j := CreateLabel("jmp") 16 p := a.CreateProgram() 17 p.JMP (j) 18 p.JMP (j) 19 p.Link (b) 20 p.Data (bytes.Repeat([]byte { 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }, 15)) 21 p.Data ([]byte { 0x0f, 0x1f, 0x00 }) 22 p.JMP (b) 23 p.Link (j) 24 p.LEAQ (Ref(s), RDI) 25 p.MOVSLQ (Sib(RDI, RAX, 4, -4), RAX) 26 p.ADDQ (RDI, RAX) 27 p.JMPQ (RAX) 28 p.Align (32, expr.Int(0xcc)) 29 p.Link (s) 30 p.Long (expr.Ref(s.Retain()).Sub(expr.Ref(j.Retain()))) 31 p.Long (expr.Ref(s.Retain()).Sub(expr.Ref(b.Retain()))) 32 spew.Dump(p.AssembleAndFree(0)) 33 }