Skip to content

Introduction

gmolin edited this page Apr 17, 2020 · 4 revisions

A short introduction to history

In 1984, an article by Andrew Dewdney appeared in Scientific American magazine describing the game "Core Wars". The article began with the following words:

Two programs in their natural habitat-computer memory-chasing each other from address to address. Sometimes they track down the enemy; sometimes they lay batteries of digital bombs; sometimes they copy themselves to another place in memory to avoid danger or stop to repair the damage done by the enemy. I call this game "Core Wars" ...

Corewar Project Overview

On the basis of this rather popular game the "Corewar" project was built, consisting of three mandatory parts:

  • The Champion
  • The Assembler
  • The Virtual Machine

The Champion

The main goal of this section is to write assembly language code, which will then be placed in a file with the .s extension.

In fact, we are writing code in a pseudo-assembler language. That is, in a language created specifically for this task, which is similar to a real assembler, but still it is not. However, for the sake of consistency with the text of the assignment, simplicity and in order to save six letters, we will also call this language assembler.

The generated code will be our champion, whose goal is to fight with other champions written by us or by other people.

The code of each champion has the following structure:

  1. Name
  2. Commentary
  3. Executable Code

It may look, for example, like this:

.name "Batman"
.comment "This city needs me"

loop:
        sti r1,%: live,% 1
live:
        live% 0
        ld% 0, r2
        zjmp%: loop

In this project, our goal is not to create the most powerful and invincible champion. This is a task for a completely different project called "Corewar Championship".

In "Corewar" we create our champion only to demonstrate the understanding of the topic and the ability to write code in assembly language. And not so that he could defeat someone.

Our task is to write the code without errors so that the asm program can turn it into bytecode, which the virtual machine would then execute.

There are no goals to win the battle or to demonstrate at least some worthy result in the battle.

The Assembler

The objective of this section is to create a program that will translate champion code written in assembly language into bytecode - a bunch of numbers in hexadecimal notation.

This task can be interpreted as "translate commands from human (assembler) language into a language that is understandable by a virtual machine (byte code)."

Translation of the program - is a conversion of code from one computer language into another. Translator usually performs error diagnostics, generates identifier dictionaries, prints out the program text, etc.

Source: Translator - Wikipedia

By that means we must create a program with the name asm (from the word "assembler"), which will receive a file as parameter containing assembly code and based on it generate a new file containing bytecode.

The file with the code of our champion, written in assembler, must have the extension .s. The program asm will create a new file with the extension .cor, where the created bytecode will be located.

The name of the file itself will remain unchanged. That is, after calling the ./asm batman.s command, the batman.cor file should appear next to the batman.s file, unless there is an error during the translation.

The Virtual Machine

After we received the file with bytecode, it is time for our virtual machine.

A virtual machine is a program whose executable file should be called corewar.

Its task is to allocate a specific plot of memory, place the code of champions and carriages that will execute champions' code in this memory section.

And then it should follow the progress of the battle and declare the winner champion after its completion.

Bonuses

As always, the number of bonuses and their content is limited solely by the imagination of authors.

Here are a few ideas that could be implemented:

Extended error messages

If an error occurred during the generation of the bytecode, it is advisable that in this case the asm program behaves like a real translator, which it actually is. That is, it should produce a meaningful message - on which line of .s file an error occurred and what its type is.

Ability to disassemble bytecode

To make it possible to obtain source code in assembler by having a file with bytecode. That is, to implement an inverse function of asm program.

Visualizer

Create a program that will display the state of memory, as well as key game parameters during the battle.

Various sound effects can also be added to focus on key points such as carriage death or a winner announcement.