Skip navigation


Page Content:

Vorwort - Tutorial

Introduction to programming by the means of Corewars and Redcode

This chapter is a discussion about the basic principles, how computers work in view of Core War programming. If you are experienced with Core Wars, you don't need to read these pages. If you already know what machine language is, you might want to read about the specifications of a MARS-CPU

To understand this tutorial, you should know about computer basics already. This introduction only tries to show some specific aspects of the way computers work. If you are not familiar with writing programs, you came to the right place.

This chapter explains the following topics:

About Programming Languages

Programs written in an assembly languageExternal Link are different to programs written in any high level programming languageExternal Link like BASIC, Pascal, JavaScript or C++. Imagine every command of those languages as a place holder for the corresponding machine opcodesExternal Link (Commands, the processor can execute). A program, called "compilerExternal Link", translates the source code of the program into a machine program before execution. Programs written in Assembler also need to be translated into the binary machine format, but the commands in the source code represent machine opcodes. Using Assembler, a programmer can take advantage of the processor's features and get the optimum performance. While compilers are not as good in creating fast machine code as humans are, they allow easy and quick program development.

Most programs today are written in high level programming languages, except for special programs like hardware drivers. If you want your computer to display a text, you can write the BASIC command: PRINT "Hello, World!". In machine language this task is more complex; The program has to copy each character of the text into the memory of the video hardware. You won't let every character be transferred by an individual MOV command, but you will create a certain mechanism, that can copy any text from any location of the memory to another. Thus you will get a sub-routine that can be reused for displaying any text.

Those of you, who already have written programs in a high level language, may wonder, what programming in assembly language is useful after all. The simple answere is: You can play Core War with it. Just kidding. Machine programs are written by humans or compiler programs. If written by an expert, they are as fast (or memory saving) as they can be. At least they should be. Assembler is mostly used when a program intensively has to communicate with certain hardware components or in time critical applications like Games, 3D graphic applicationsExternal Link, mathematical software or specific parts of an operating system. Modern high level programming languages allow to assembler code sections to be included in the program source code. (Inline AssemblerExternal Link)

There is a third way of having a program executed: The source text can be interpreted by another software, called the interpreterExternal Link (like JavaScript or BASIC). The translation of the program is not done before start, but the commands of the source file are being analysed individually in runtime (while the program is being executed). This is surely the slowest way of execution, but provides the most flexibility for programmers and users.

Redcode Assembler

Most examples of this tutorial can not be entered to the simulator's core in the way, they are presented. They contain additional information for the preprocessorExternal Link. Such programs need to be stored in text files, because they are read in and translated into the Core Memory by the assembler of ARES before a battle starts.

Parts of these source files, which are written behind a semicolon (";"), are ignored by the assembler. They are meant as documentary comments for the program writer. There is an exception for this rule - so called "assembler directives" provide further information for certain core war programs.

By default, ARES displays the contents of the "Monitor-View" in a certain shortened way. The ICWS-88 standard did not allow to use every possible part of the memory, like in the command JMP +1. Most opcodes in Redcode use two operands, but JMP only takes one: the target address ("+1"). But ICWS-94 compatible programs are allowed to use these "invisible" memory gaps, so you might want to see the whole content of every memory location. You can switch between ICWS-88 and ICWS-94 view by hitting Strg-O. The examples of this tutorial are shown in their short version, when the full '94-features aren't used. This difference affects the "Monitor-View" mainly: If a value is not displayed, it doesn't mean, that it is not there. If you type in an opcode, the possible missing second operand is automatically created corresponding to the opcode modifiers

Machine Language

Content Management:

μCMS α1.6