Giter Club home page Giter Club logo

nasmfmt's Introduction

nasmfmt

Automatically format your assembly sources with a simple command.

Inspired by gofmt.

What it does?

In one example. This source:

global _start


section .text

   ;Starting point
_start:
mov rax,1 ;write(fd, buf, len)
mov rdi,1  ; fd
mov rsi, msg   ; buf
mov rdx,  msglen; len
  syscall

mov rax,60 ;exit(status)
mov rdi, 0
  syscall

section .data
msg    db "Hello world!",10
msglen equ $-msg

Would be formatted into:

        global _start

        section .text

; Starting point
_start:
        mov rax, 1                     ; write(fd, buf, len)
        mov rdi, 1                     ; fd
        mov rsi, msg                   ; buf
        mov rdx, msglen                ; len
        syscall

        mov rax, 60                    ; exit(status)
        mov rdi, 0
        syscall

        section .data
msg:
        db "Hello world!", 10
        msglen equ $-msg

Features

  • Labels and instructions indentation.
label:
add rax, rbx

Becomes:

label:
        add rax, rbx
  • Comments indentation.
   ; Start of the cycle
cycle:
        inc rcx ; Make it bigger
        jmp cycle ; Because why not?
                  ; Here's no cycle

Becomes:

; Start of the cycle
cycle:
        inc rcx                        ; Make it bigger
        jmp cycle                      ; Because why not?
; Here's no cycle
  • Consistent labels style.
one_style: test rax, rbx
another_style:
        test rax, rbx

one_style:
        db "Message"
another_style db "Message"

Becomes:

one_style:
        test rax, rbx
another_style:
        test rax, rbx

one_style:
        db "Message"
another_style:
        db "Message"
  • Consistent commas style.
        add rax,rbx
        add rax, rbx
        add rax,  rbx

Becomes:

        add rax, rbx
        add rax, rbx
        add rax, rbx
  • No extra spaces and empty lines.
add_func:
        mov    rax, rdi
        add    rax, rsi
        ret



sub_func:
        mov    rax, rdi
        sub    rax, rsi
        ret

Becomes:

add_func:
        mov rax, rdi
        add rax, rsi
        ret

sub_func:
        mov rax, rdi
        sub rax, rsi
        ret

Issues

There might be some issues since I have not tested it on all nasm functionality. Please, report, if you found some.

Would it work with other assemblers? May be, since most assembly syntaxes are similar.

Usage

Usage: nasmfmt [params] [file1 [file2 ...]]
Parameters:
  -ci int
        Indentation for comments in spaces (default 40)
  -ii int
        Indentation for instructions in spaces (default 8)

Examples:

  • nasmfmt main.asm funcs1.asm funcs2.asm
  • nasmfmt -ii 4 main.asm
  • nasmfmt -ii 4 -ci 36 main.asm

Installing

Visit Releases to download a binary for your platform.

Building

Building requires latest version of golang from golang.org.

If you installed one, run go get -u github.com/yamnikov-oleg/nasmfmt. Built binary will be located in your $GOPATH/bin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.