Home
The Ant Guide
FAQ
Releases/Downloads
Course Materials
Ant Users
General Documentation
Papers about Ant
Related Links

A Guide to Ant-8

 

Ant is a simple virtual machine architecture that we use in teaching many fundamental concepts in our CS1 courses, and our introductory computer architecture course. Ant is similar enough to a modern RISC architecture that the techniques learned using Ant are applicable to real systems. At the same time, Ant is simple enough for students to master quickly. In a few short weeks, we have CS1 students writing simple Ant programs, building an Ant virtual machine, and implementing an Ant assembler.

Why Do We Use Ant?

Many of the students in our CS1 course have conceptual problems that make it difficult for them to master the material on our syllabus. In particular:

  • Students have difficulty understanding memory and pointers in languages like C or C++.

  • Students often have bad intuition about how computers actually work:

    • How data and programs are represented

    • How computer programs are executed

Our solution to these problems is to spend some time teaching computer architecture in CS1. We believe that computer architecture is a fundamental topic that should appear early in the CS curriculum; our CS1 syllabus discusses computer architecture in the fifth week, after the basic elements of programming have been covered but before pointers and recursion are introduced.

We consider the following topics to be essential to CS1:

  • Data and program representation:

    • Binary notation and arithmetic

    • How programs can be represented in machine language and interpreted in a completely mechanical manner

  • The fundamentals of computer architecture:

    • CPU organization (ALU, registers, datapath)

    • Memory

    • Peripherals (disk, network, keyboard, mouse, screen, sound)

  • Virtual machines

  • Assembly language programming

A question that is often raised about our syllabus is why we teach assembly language-- after all, assembly language is used only rarely today, and few of our students will ever write assembly language code after taking our course. The reason that we teach assembly language is because it is a powerful pedagogical tool that can provide deep insight into the principles behind many contemporary programming languages and practices:

  1. Assembly language illustrates pointers.

    Pointers are one of the most difficult concepts for novice students to grasp. Once students have written assembly language code to implement address arithmetic and have used load and store instructions, pointers and addresses in higher-level languages become much more intuitive.

  2. Assembly language teaches essential design skills and style.

    Even very short pieces of assembly language code are difficult to write unless they are well designed and structured, and nearly impossible to read unless properly documented. The exercise of writing some short assembly language programs focuses on the design and style skills we try to teach in CS1, and seems to have beneficial effects on the way that students approach their larger programming assignment later in the semester.

  3. Assembly language makes clear the architecture of the underlying machine.

    Understanding the underlying machine demystifies the computer and programming in assembly language helps students understand how extremely complex programs can be reduced to sequences of very simple instructions.

Our assembly language programming exercises from 1998 and 1997 underscore these points.

A Description of Ant

Not all assembly languages are well-suited to pedagogical purposes. Most are too complex, idiosyncratic, or arcane. For our purposes, we require an assembly language with the following properties:

  1. Small, simple, and easy to teach

    If the assembler takes more than a few lectures to explain, it takes valuable class time from other topics. We treat assembly language as a tool to illustrate the main topics of the course-- assembly language itself is not a main topic.

  2. A realistic instruction set, mnemonics, and assembler syntax

  3. A complete and well-documented development environment

We could not find a system that met our requirements, so we created Ant to satisfy our needs.

The Ant Architecture

Ant is a ``typical'' RISC architecture. It is inspired by the MIPS R2000 architecture, but greatly simplified.

Some of the important characteristics are:

  • 16-bit fixed-format instructions
  • 14 8-bit general purpose registers and two special-purpose registers
  • Three-address, register-to-register arithmetic operations
  • Single address mode for load/store operations
  • Simple branch conditions
The most important simplifications are listed below:
  • Very small (8-bit) address space
  • No floating point support
  • No pipeline, cache, etc.
  • No explicit stack pointer, frame pointer, or register use conventions.

These simplifications produce an architecture that is very easy to learn, and yet is still powerful enough to use as realistic illustration of a computer architecture and to run interesting, non-trivial programs.

The Ant Instruction Set

Instruction Type Name Description
Arithmetic





add
sub
mul
and
nor
shf
Signed addition
Signed subtraction
Signed multiplication (with overflow)
Bitwise AND
Bitwise NOR
Arithmetic Shift
Branch


beq
bgt
jmp
Branch if equal
Branch if greater than
Unconditional branch
Memory

ld1
st1
Load register from memory
Store register to memory
Immediate

lc
inc
Load constant into register
Increment register by constant
System Calls


hlt
in
out
Halt the Processor
Read a Character
Write a Character

The instruction set and assembly language is introduced in a tutorial manner by the Ant Tutorial. A more detailed description of each instruction is given in the Ant Architecture Reference.

Ant Development Tools

The Ant development environment contains four tools: an assembler that converts programs written in Ant assembly language into Ant machine language, a simulator that can execute Ant programs, a debugger for Ant programs, and an integrated development environment that provides a graphical user interface to all of these tools.

aide8 is an integrated development environment for Ant-8, including an editor and debugger.

The assembler has many useful error and warning messages that indicate the location of any syntax errors in an Ant program, and provide hints for how to fix them. Students can write their own assembler; this is a very challenging assignment for CS1, but a reasonable assignment for CS2.

The simulator implements a virtual Ant, and runs Ant programs with the same behavior as an Ant would, allowing Ant programs to be run unmodified on a variety of different hardware/software platforms. Students can also write their own simulator. This is a very nice exercise for two reasons-- it reinforces and increases understanding of virtual machines and how programs are executed, and students find this to be the most interesting and engaging weekly assignment of the semester.

The commandline Ant debugger is primarily used for helping debug Ant programs, but it can also be used to illustrate the process of executing an Ant program.

 

If you have any questions or comments about this page or Ant, please contact the Ant developers.

The ANT project was funded by NSF grant DUE-9950239 and Microsoft corporation.