https://github.com/kvakil/0asm
x86 assembler in 512 bytes of x86 machine code
https://github.com/kvakil/0asm
assembler assembly demoscene x86
Last synced: 6 months ago
JSON representation
x86 assembler in 512 bytes of x86 machine code
- Host: GitHub
- URL: https://github.com/kvakil/0asm
- Owner: kvakil
- License: gpl-3.0
- Created: 2019-11-20T06:24:03.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-01T21:08:04.000Z (almost 6 years ago)
- Last Synced: 2025-03-29T07:22:37.915Z (7 months ago)
- Topics: assembler, assembly, demoscene, x86
- Language: Assembly
- Homepage:
- Size: 170 KB
- Stars: 33
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/nanochess/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 .