{"id":19729353,"url":"https://github.com/wdamron/x64","last_synced_at":"2025-04-30T01:32:01.259Z","repository":{"id":57495610,"uuid":"173663920","full_name":"wdamron/x64","owner":"wdamron","description":"x86-64 instruction encoder in Go","archived":false,"fork":false,"pushed_at":"2019-11-02T16:27:41.000Z","size":356,"stargazers_count":21,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T08:07:29.587Z","etag":null,"topics":["assembler","go","instruction-encoding","jit","x86","x86-64"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wdamron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-04T03:01:44.000Z","updated_at":"2024-03-13T13:43:27.000Z","dependencies_parsed_at":"2022-08-31T14:24:22.982Z","dependency_job_id":null,"html_url":"https://github.com/wdamron/x64","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Fx64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Fx64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Fx64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Fx64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wdamron","download_url":"https://codeload.github.com/wdamron/x64/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224193109,"owners_count":17271238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembler","go","instruction-encoding","jit","x86","x86-64"],"created_at":"2024-11-12T00:11:45.107Z","updated_at":"2024-11-12T00:11:45.590Z","avatar_url":"https://github.com/wdamron.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# x64\n\nx86-64 instruction encoder in Go (work in progress)\n\nThis package contains a more-or-less direct port of the instruction-encoding logic from [CensoredUsername/dynasm-rs](https://github.com/CensoredUsername/dynasm-rs). Only a relatively small subset of the features in `dynasm-rs` are supported. Not many features are working or tested yet, but the intended use-case is assembling executable code at runtime.\n\nSee the [godocs](https://godoc.org/github.com/wdamron/x64) or otherwise look at the tests for usage examples.\n\n## \"Basic\" Usage\n\n```go\npackage example\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t// importing everything from the package into the current scope makes for less noise\n\t. \"github.com/wdamron/x64\"\n\t\"golang.org/x/sys/unix\"\n)\n\nconst (\n\tANON_PRIVATE = unix.MAP_ANON|unix.MAP_PRIVATE\n\n\tREAD_WRITE = unix.PROT_READ|unix.PROT_WRITE\n\tREAD_EXEC  = unix.PROT_READ|unix.PROT_EXEC\n)\n\nfunc CompileSumFunc() (func(a, b int) int, error) {\n\tmem, err := unix.Mmap(-1, 0, os.Getpagesize(), READ_WRITE, ANON_PRIVATE)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"sys/unix.Mmap failed: %v\", err)\n\t}\n\n\tasm := NewAssembler(mem)\n\n\t// Note: the call frame (arguments and returned value) starts at [RSP+8].\n\t// The return address will be stored at [RSP].\n\n\tasm.Inst(MOV, RAX, Mem{Base: RSP, Disp: Rel8(8)})   // RAX := a+0(FP)\n\tasm.Inst(MOV, RBX, Mem{Base: RSP, Disp: Rel8(16)})  // RBX := b+8(FP)\n\tasm.Inst(ADD, RAX, RBX)                             // RAX += RBX\n\tasm.Inst(MOV, Mem{Base: RSP, Disp: Rel8(24)}, RAX)  // ret+16(FP) := RAX\n\tasm.Inst(RET)                                       // return\n\tif asm.Err() != nil {\n\t\t_ = unix.Munmap(mem)\n\t\treturn nil, asm.Err()\n\t}\n\n\tif err := unix.Mprotect(mem, READ_EXEC); err != nil {\n\t\t_ = unix.Munmap(mem)\n\t\treturn nil, fmt.Errorf(\"sys/unix.Mprotect failed: %v\", err)\n\t}\n\n\tsum := (func(a, b int) int)(nil) // placeholder value\n\n\t// Assign the address of the assembled/executable code to the code-pointer within\n\t// the placeholder function-value:\n\tif err := SetFunctionCode(\u0026sum, mem); err != nil {\n\t\t_ = unix.Munmap(mem)\n\t\treturn nil, err\n\t}\n\n\treturn sum, nil\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdamron%2Fx64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwdamron%2Fx64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdamron%2Fx64/lists"}