An open API service indexing awesome lists of open source software.

https://github.com/andreiglesias/corewar

Development of a Virtual Computer, an Assembler and a Disassembler for the programming game Corewar.
https://github.com/andreiglesias/corewar

assembler assembly-language c corewar disassembler low-level-programming

Last synced: 3 months ago
JSON representation

Development of a Virtual Computer, an Assembler and a Disassembler for the programming game Corewar.

Awesome Lists containing this project

README

          


Corewar



A virtual Computer, an Assembler and a Disassembler for the programming game Corewar.



---


Introduction
Virtual Computer
Assembler
Disassembler
Bonus Features
Installation
License

![Battlefield](docs/corewar.gif?raw=true "corewar")
# Introduction

Core War was inspired by a malicious virus written in the 80’s. To deal with the self-replicating virus, a white hat hacker invented Reaper. It was a virus designed to spread and eliminate the malware. He fought fire with fire.

This inspired A. K. Dewdney to coin the idea for Core War.

The idea was simple. You compete by designing viruses to overtake a computer. You win by protecting your own program and overwriting your opponent's programs. This is all happening on a virtual computer. Think, a simple computer within your computer.

# Virtual Computer
### VM General Structure:
[![VM general structure](https://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/01/FIGS/cpu1.gif)](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/doc1.png)

[Reference](https://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/01/intro-computer2.html)

The loading of the **champions** and the **enumeration** of each player happens in the command line.

It’s important to remember that the **last player** will have the **first process** in the order of *execution*.
### VM Usage:
![vm usage](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/Usage.png)

### Champions loaded without any option:
![champion without options](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/zork.png)

### Dumping memory at given cycle:
![vm verbosity](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/verbosity.png)

## Ncurse's Display
![vm_corewar](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/corewar.png)

### Loading champions
The champions are loaded within the memory so that they can space out evenly their entry points.

At startup, each champion have their initial process at their respective entry point.

![loading champions](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/initial_process.png)

### Processes Table
The **number** (*id*) of the player is generated by the machine or specified at launch, and is given to the champions via the **r1 registry** of their first process at startup.

![processes](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/process_reg.png)

So even if the champion has *no instructions*, it will be able to participate as a contestant with the help of the **initial process** and the registry **r1** which has its player’s id.

# Assembler

The **assembler** (*asm*) translates the champion's code to bytecode.

### zork.s:

zork_code

### champion's header and the Magic Number:

![header with magic number](https://github.com/AndreIglesias/Corewar/blob/master/docs/img/MAGIC_EXEC.png)

### champion's instructions in bytecode:

zork_body

### asm with the -v option
The **asm** translates the champion into a *.cor bytecode file*, as usual, but also displays in the standard output, the **syntax table** with translation of each instruction to the right.

asm v

## Disassembler

The **disassembler** takes a *.cor bytecode file* and translates into a *.s assembly file*.

### Assembling a disassembled zork.cor:
disasm

## Bonus Features

1. (vm) ncurse’s interface visualizer
2. (vm) verbose and formatted output (-v)
3. (asm) a detailed syntax table display (-v)
4. (asm) beautiful error message when assembling
+ with line numbers, and a cursor to show where is the error
+ differentiating between **lexical** and **syntactical** error.
+ syntax error
+ lexicon error
5. (other) disassembler
6. (other) org documentation
+ lexicon error
# Installation
```bash
# Clone this repository
$ git clone --recurse-submodules https://github.com/AndreIglesias/Corewar
# Go into the repository
$ cd Corewar
# Compile the project
$ make
```

## License

> [GPL v3.0](https://github.com/AndreIglesias/Corewar/blob/master/LICENSE)  · 
> [@AndreIglesias](https://github.com/AndreIglesias)