Skip to content

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

License

Notifications You must be signed in to change notification settings

AndreIglesias/Corewar

Repository files navigation

Corewar

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


IntroductionVirtual ComputerAssemblerDisassemblerBonus FeaturesInstallationLicense

Battlefield

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

Reference

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

Champions loaded without any option:

champion without options

Dumping memory at given cycle:

vm verbosity

Ncurse's Display

vm_corewar

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

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

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

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

# 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  ·  @AndreIglesias

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published