Git Product home page Git Product logo

0asm's Introduction

0asm

0asm is a 16-bit x86 assembler written in 16-bit x86 assembly which fits in under 512 bytes of x86 machine code! It runs on bootOS.

Assembling

You can assemble and run 0asm using nasm and QEMU (respectively):

make run

This also copies the input file test.asm into the disk under the filename 0. One can then run the assembler in bootOS:

$0asm

and then run the output program under @:

$@
Hello, world! $

Further examples are available under the examples/ directory.

Anticipated FAQ

What does it support?

0asm supports several common instructions, labels (absolute and relative relocations), and octal literals (but only octal literals). It also supports all 16-bit x86 general purpose registers, but does not support segment registers.

Many jump instructions are supported (call, jmp, jb, jnb, jz, jnz, jbe, jnbe), along with several string instructions (stosb, stosw, lodsb, lodsw, movsw, cbw, scasw), several stack instructions (push, pop, ret), a few fundamental arithmetic instructions in both register/register and register/immediate form (add, or, adc, and, xor, cmp, mov), and some misc instructions (int, stc, inc, dec, the pseudo-instruction db).

Errors are not always handled, but the assembler does usually exit cleanly instead of producing garbage.

How does it work?

0asm is a simple 2-pass assembler. The first pass outputs the machine code for instructions which do not require any relocation; it also collects labels into a "symbol table", and the addresses of immediates which need to be fixed into a "fixup table". The first pass also outputs the machine code for instructions which do not require any relocation.

Is it self-hosting?

Unfortunately not yet, for several reasons.

  1. The underlying bootOS only supports 512 byte files.
  2. The instruction encoding produced is not optimal, so it will not fit in 512 bytes once assembled.
  3. Shift and memory-addressing instructions are not yet supported.

These problems are not insurmountable, although it seems difficult. We could easily move the goalpost by typing the entire program using db, but of course that would be no fun.

Development

The code is decently commented. Many of the files in this repo are generated from 0asm.asm, including the README. You can also debug by running make debug (to start QEMU in one pane) and make gdbdebug (to start GDB along with some helpful default scripts).

License

Copyright (c) 2019 Keyhan Vakil

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

0asm's People

Contributors

kvakil avatar

Forkers

jbro885

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.