asm

所属分类:嵌入式/单片机/硬件编程
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2022-08-10 02:40:56
上 传 者sh-1993
说明:  用Go.编写的x86-64汇编程序。,
(An x86 -64 assembler written in Go.,)

文件列表:
.drone.yml (478, 2022-08-09)
Add.go (878, 2022-08-09)
Add_test.go (6661, 2022-08-09)
Address.go (112, 2022-08-09)
Assembler.go (3824, 2022-08-09)
Assembler_test.go (852, 2022-08-09)
Call.go (605, 2022-08-09)
Compare.go (1770, 2022-08-09)
Compare_test.go (9041, 2022-08-09)
Div.go (298, 2022-08-09)
Div_test.go (2586, 2022-08-09)
Increase.go (1261, 2022-08-09)
Increase_test.go (4838, 2022-08-09)
Jump.go (2698, 2022-08-09)
Jump_test.go (896, 2022-08-09)
LICENSE (1070, 2022-08-09)
Label.go (298, 2022-08-09)
Load.go (2172, 2022-08-09)
Load_test.go (4644, 2022-08-09)
Move.go (1146, 2022-08-09)
Move_test.go (9419, 2022-08-09)
Mul.go (821, 2022-08-09)
Mul_test.go (5571, 2022-08-09)
Other.go (544, 2022-08-09)
Pointer.go (312, 2022-08-09)
Push.go (879, 2022-08-09)
Push_test.go (2655, 2022-08-09)
SignExtend.go (336, 2022-08-09)
SignExtend_test.go (477, 2022-08-09)
Store.go (2473, 2022-08-09)
Store_test.go (13485, 2022-08-09)
Sub.go (882, 2022-08-09)
Sub_test.go (6661, 2022-08-09)
Syscall.go (1263, 2022-08-09)
bitsNeeded.go (388, 2022-08-09)
elf/ (0, 2022-08-09)
elf/Header64.go (867, 2022-08-09)
... ...

# asm [![Godoc][godoc-image]][godoc-url] [![Report][report-image]][report-url] [![Tests][tests-image]][tests-url] [![Coverage][coverage-image]][coverage-url] [![Sponsor][sponsor-image]][sponsor-url] An x86-64 assembler written in Go. It is used by the [Q programming language](https://github.com/akyoto/q) for machine code generation. It was born out of the need for a highly performant assembler that had next to no overhead when compiling instructions to bytecode. When I started this project, I had no idea of how x86 instructions were constructed and I was forced to do a lot of reverse engineering via NASM. Hopefully this repository helps someone who is learning about x86 assembly and its bytecode format. There are a few [examples](https://github.com/akyoto/asm/tree/master/examples) to get an idea of the API I was aiming for. ## x86-64 bytecode An x86-64 program consists of a list of instructions. All of these instructions are built with the following format: | Name | Size in bytes | Required? | |-----------------|---------------|-----------| | Legacy prefixes | 1-4 | | | OP code | 1-4 | required | | Mod/RM | 1 | | | SIB | 1 | | | Displacement | 1-8 | | | Immediate | 1-8 | | Out of these only the actual OP code which decides the instruction to execute is required. The remaining components depend on what instruction and what kind of parameters you have. The maximum size for a single instruction is limited to 15 bytes. ### Mod/RM The Mod/RM byte has the following format: | Name | Size in bits | |------|--------------| | Mod | 2 | | Reg | 3 | | RM | 3 | ```go (mod << 6) | (reg << 3) | rm ``` ### SIB The SIB byte has the same format as Mod/RM, just with different meanings: | Name | Size in bits | |-------|--------------| | Scale | 2 | | Index | 3 | | Base | 3 | ```go (scale << 6) | (index << 3) | base ``` The `opcode` directory has a few helper functions to construct these components. ## Registers The following is a list of register names you can use. I decided to stick with the original names instead of r0-r7 for rax-rbp. I might still switch to r0-r7 for the future and enable the old names as synonyms. | 64 bit | 32 bit | 16 bit | 8 bit | |--------|--------|--------|-------| | rax | eax | ax | al | | rcx | ecx | cx | cl | | rdx | edx | dx | dl | | rbx | ebx | bx | bl | | rsi | esi | si | sil | | rdi | edi | di | dil | | rsp | esp | sp | spl | | rbp | ebp | bp | bpl | | r8 | r8d | r8w | r8b | | r9 | r9d | r9w | r9b | | r10 | r10d | r10w | r10b | | r11 | r11d | r11w | r11b | | r12 | r12d | r12w | r12b | | r13 | r13d | r13w | r13b | | r14 | r14d | r14w | r14b | | r15 | r15d | r15w | r15b | ## Resources * https://godbolt.org * https://www.felixcloutier.com/x86 * https://wiki.osdev.org/X86-64_Instruction_Encoding * https://www.systutorials.com/beginners-guide-x86-64-instruction-encoding/ * https://blog.yossarian.net/2020/06/13/How-x86_64-addresses-memory * https://cs.brown.edu/courses/cs033/docs/guides/x64_cheatsheet.pdf * https://www.cs.cmu.edu/~fp/courses/15213-s07/resources.html * https://www.agner.org/optimize/optimizing_assembly.pdf * https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html [godoc-image]: https://godoc.org/github.com/akyoto/asm?status.svg [godoc-url]: https://godoc.org/github.com/akyoto/asm [report-image]: https://goreportcard.com/badge/github.com/akyoto/asm [report-url]: https://goreportcard.com/report/github.com/akyoto/asm [tests-image]: https://cloud.drone.io/api/badges/akyoto/asm/status.svg [tests-url]: https://cloud.drone.io/akyoto/asm [coverage-image]: https://codecov.io/gh/akyoto/asm/graph/badge.svg [coverage-url]: https://codecov.io/gh/akyoto/asm [sponsor-image]: https://img.shields.io/badge/github-donate-green.svg [sponsor-url]: https://github.com/users/akyoto/sponsorship

近期下载者

相关文件


收藏者