Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xyproto/battlestar
:dizzy: A different take on Assembly, with the goal of creating tiny executables.
https://github.com/xyproto/battlestar
assembly dosbox gcc inline linux programming-language tiny
Last synced: 22 days ago
JSON representation
:dizzy: A different take on Assembly, with the goal of creating tiny executables.
- Host: GitHub
- URL: https://github.com/xyproto/battlestar
- Owner: xyproto
- License: bsd-3-clause
- Created: 2014-02-20T16:49:03.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T10:28:09.000Z (11 months ago)
- Last Synced: 2024-12-24T19:32:00.752Z (about 1 month ago)
- Topics: assembly, dosbox, gcc, inline, linux, programming-language, tiny
- Language: Go
- Homepage:
- Size: 677 KB
- Stars: 80
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-programming-languages - Battlestar - Subset of assembly with an alternative syntax and with support for inline C, specifically for 64-bit x86 Linux, 32-bit x86 Linux and 16-bit x86 DOS. (Uncategorized / Uncategorized)
README
Battlestar
==========[![License](http://img.shields.io/badge/license-BSD-green.svg?style=flat)](https://raw.githubusercontent.com/xyproto/battlestar/main/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/battlestar)](https://goreportcard.com/report/github.com/xyproto/battlestar)What is Battlestar?
-------------------* A programming language specifically for 64-bit x86 Linux, 32-bit x86 Linux and 16-bit x86 DOS.
* Subset of assembly with an alternative syntax and with support for inline C.
* A work in progress.
* Created for fun and for the educational process.
* The indended purpose is for writing small operating systems, 1k and 4k demoscene demos.Quick start
-----------Build and install Battlestar, build the samples and run the "life" sample:
* `make; sudo make devinstall; make samples; cd life; ./life.sh; cd ..`
This requires DosBox, Go, Yasm and GCC.
Build and boot a kernel (requires GCC, Yasm, Battlestar and the `qemu-system-i386` executable):
* `cd kernel/simple; make boot; cd ../..`
Features and limitations
------------------------* The resulting executables are tiny!
* "hello world" is only *174* bytes for 32-bit Linux (when using sstrip from elfkickers). (238 bytes for 64-bit Linux, 31 bytes for 16-bit DOS)
* It's possible to write an operating system / kernel with only one source file.
* Full support for inline C (by utilizing gcc).
* C and Battlestar code can exist in the same source file and calls can be made both ways.
* Battlestar programs compiles almost instantly.
* Programs can be run like scripts by including this line at the top: ```#!/usr/bin/bts```
* Interrupts can be called with the same syntax for both 32-bit and 64-bit x86 on Linux.
* Supports 16-bit x86 that can run within DosBox.
* The intermediate assembly is fully commented.
* No register allocator, just an alternative assembly syntax.
* `gccgo` is not supported yet.Sample program
--------------This is a 16-bit x86 program, for DOS:
```c
// "Life"
// The original was written by "melezov" (http://256bytes.untergrund.net/demo/334)fun main
al = 0x13 // set graphics mode (mode 13h)
// 320x200, 256 colors, one byte per pixel
int 10stack -> sp // pop sp
stack -> b // pop bx
stack -> ds // pop dsds -> es // push ds, pop es
al = 62
ch = 0xFA
loopwrite // rep stosbloop
di <<< 3 // rotate left 3
di -= 7 // subtraction
di ^= 2 // xoral = readbyte di // read byte from memory
al += [di+321] // add value at [di+321] (pixel on the line below)
al /= 2di -> stack
write // stosb
writedi += 0x13E
write
writestack -> di
end // loops forever
end
```In progress
-----------* macOS support
* Reimplementing 16-bit demoscene demos without using any inline assembly
* See TODOInstallation
------------------Make sure Go, Yasm and GCC are installed.
Installation:
`sudo make PREFIX=/usr install`
For development, install soft links instead:
`sudo make install-dev`
Build all the samples:
`make samples`
Build dependencies
------------------* go >= 1.3
Runtime dependencies
--------------------* yasm
Optional runtime dependencies
-----------------------------
* gcc (for inline C support)
* elftools/sstrip (for even smaller binaries)
* binutils (for disassembling with objdump)
* dosbox (for running 16-bit executables) (only GCC 4.9 and up supports compiling to 16-bit with -m16)
* SDL 2 (must be compiled and installed manually if on Red Hat 6)
* tcc (for even smaller binaries, in many cases)External links
--------------* Battlestar programs on [Rosetta Code](https://rosettacode.org/wiki/Category:Battlestar#mw-pages)
General info
------------* Version: 0.7.0
* License: BSD-3
* Author: Alexander F. Rødseth <[email protected]>