• Stars
    star
    247
  • Rank 158,373 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go Assembler Formatter

asmfmt

Go Assembler Formatter

This will format your assembler code in a similar way that gofmt formats your Go code.

Read Introduction: asmfmt: Go Assembler Formatter

Go Reference Go

See Example 1, Example 2, Example 3, or compare files in the testdata folder.

Status: STABLE. The format will only change if bugs are found. Please report any feedback in the issue section.

install

Binaries can be downloaded from Releases. Unpack the file into your executable path.

To install the standalone formatter from source using Go framework: go install github.com/klauspost/asmfmt/cmd/asmfmt@latest.

updates

  • Apr 8, 2021: Add modules info and remove other than main tools.
  • Jan 6, 2021: Fix C comments before line comments like VPCMPEQB Y8/*(DI)*/, Y0, Y1 // comment...
  • Aug 8, 2016: Don't indent comments before non-indented instruction.
  • Jun 10, 2016: Fixed crash with end-of-line comments that contained an end-of-block /* part.
  • Apr 14, 2016: Fix end of multiline comments in macro definitions.
  • Apr 14, 2016: Updated tools to Go 1.5+
  • Dec 21, 2015: Space before semi-colons in macro definitions is now trimmed.
  • Dec 21, 2015: Fix line comments in macro definitions (only valid with Go 1.5).
  • Dec 17, 2015: Comments are better aligned to the following section.
  • Dec 17, 2015: Clean semi-colons in multiple instruction per line.

goland

To set up a custom File Watcher in Goland,

  • Go to Settings -> Tools -> File Watchers
  • Press + and choose <custom> template.
  • Name it asmfmt
  • File Type, Select x86 Plan 9 Assembly file (it will apply to all platforms)
  • Scope: Project Files
  • Arguments: $FilePath$.
  • Output Paths to Refresh: $FilePath$
  • Working Directory: $ProjectFileDir$

Advanced options, Enable:

  • Trigger the watcher regardless of syntax errors (IMPORTANT)
  • Create output file from stdout

Disable the rest.

Goland Configuration

emacs

To automatically format assembler, in .emacs add:

(defun asm-mode-setup ()
  (set (make-local-variable 'gofmt-command) "asmfmt")
  (add-hook 'before-save-hook 'gofmt nil t)
)

(add-hook 'asm-mode-hook 'asm-mode-setup)

usage

asmfmt [flags] [path ...]

The flags are similar to gofmt, except it will only process .s files:

	-d
		Do not print reformatted sources to standard output.
		If a file's formatting is different than asmfmt's, print diffs
		to standard output.
	-e
		Print all (including spurious) errors.
	-l
		Do not print reformatted sources to standard output.
		If a file's formatting is different from asmfmt's, print its name
		to standard output.
	-w
		Do not print reformatted sources to standard output.
		If a file's formatting is different from asmfmt's, overwrite it
		with asmfmt's version.

You should only run asmfmt on files that are assembler files. Assembler files cannot be positively identified, so it will mangle non-assembler files.

formatting

  • Automatic indentation.
  • It uses tabs for indentation and blanks for alignment.
  • It will remove trailing whitespace.
  • It will align the first parameter.
  • It will align all comments in a block.
  • It will eliminate multiple blank lines.
  • Removes ; at end of line.
  • Forced newline before comments, except when preceded by label or another comment.
  • Forced newline before labels, except when preceded by comment.
  • Labels are on a separate lines, except for comments.
  • Retains block breaks (newline between blocks).
  • It will convert single line block comments to line comments.
  • Line comments have a space after //, except if comment starts with +.
  • There is always a space between parameters.
  • Macros in the same file are tracked, and not included in parameter indentation.
  • TEXT, DATA and GLOBL, FUNCDATA, PCDATA and labels are level 0 indentation.
  • Aligns \ in multiline macros.
  • Whitespace before separating ; is removed. Space is inserted after, if followed by another instruction.

More Repositories

1

compress

Optimized Go Compression Packages
Go
4,247
star
2

reedsolomon

Reed-Solomon Erasure Coding in Go
Assembly
1,728
star
3

pgzip

Go parallel gzip (de)compression
Go
1,045
star
4

cpuid

CPU feature identification for Go
Go
863
star
5

ryzen-master-vbs-patch

AMD Ryzen Master Hyper-V VBS patcher
Go
355
star
6

readahead

Asynchronous read-ahead for Go readers
Go
216
star
7

dedup

Streaming Deduplication Package for Go
Go
186
star
8

geoip-service

A fast in-memory http microservice for looking up MaxMind GeoIP2 and GeoLite2 database
Go
74
star
9

crc32

CRC32 hash with x64 optimizations
Go
73
star
10

rawspeed

Raw Image Decoder Library
C++
71
star
11

shutdown2

Shutdown Management package for Go v2
Go
49
star
12

password

Dictionary Password Validation for Go
Go
49
star
13

gad

Go After Dark
Go
40
star
14

shutdown

Shutdown management library for Go
Go
36
star
15

intrinsics

Experiment with Go intrinsics (NOT USABLE)
HTML
32
star
16

doproxy

Reverse Proxy for managing multiple Digital Ocean backends.
Go
30
star
17

oui

Library & Microservice for looking up manufacturers from MAC addresses.
Go
27
star
18

lctime

Finally, simple, familiar, locale-based datetime formatting.
Go
22
star
19

connect-compress

connect-go improved compression
Go
19
star
20

mman-win32

Automatically exported from code.google.com/p/mman-win32
C
10
star
21

match

Byte matching in Go
Assembly
10
star
22

gfx

Graphic Drawing Library
Go
9
star
23

bitset

Go Integer Bitset Generator
Go
4
star
24

shift

Fast bit shift helper
Go
3
star
25

simdjson-fuzz

Fuzzers and corpus for github.com/fwessels/simdjson-go
Go
3
star
26

json

Fork of the official Go JSON library that allows streaming indented output
Go
3
star
27

compress-fuzz

Fuzz data for the klauspost/compress package
Go
2
star
28

talks

Talks
Go
2
star
29

dawa

Go implementation of DAWA AWS Suite 4 (Danish Address Info)
Go
1
star