MIPS Assembly Langage (MAL) is the assembly language for MIPS processors. The MIPS processor was developed by Dr. John Hennessey and his graduate students at Stanford University in the early 1980s. Dr. Hennessey later formed the MIPS Technologies, commercializing its production. MIPS Technologies licenses the design to numerous companies that produce variations of the processor. It is currently one of the major processors in the embedded processor market.

To get a feel for MAL programming it is helpful to first get a general picture of the programming model that a MAL programmer works with. Then a simple example shows how the elements of the model are used in a MAL program. After that, the structure of a MAL program and its statements is described in more detail.

An assembly language programmer needs to define data items and how they are manipulated. The manipulations involve moving data around, transforming it in various ways, comparing data items, and making programming decisions based on comparisons. Most of these capabilities are provided directly by the computer. An assembler provides an interface to computer, its registers and memory, and the instructions that the computer can execute.

A programmer also needs to direct input to and output from a computer. In modern computer systems, input and output is always managed by an operating system.

The primary hardware components of a computer system are the processor, memory (primary storage), and I/O devices, including secondary storage. The processor consists of an arithmetic-logic unit, registers, and control circuitry. The arithmetic-logic unit (ALU) does calculations and comparisons. The registers provide a small amount of primary storage. The control circuitry controls the execution of instructions by routing data between registers, the ALU, and and external devices, and controlling the operation performed by the ALU.

MIPS Memory

MIPS, like most modern processors, has byte-addressable memory. Memory is treated as a large array of bytes. The array index of each byte is called its address. An address can also denote a larger chunk of data: 2, 4, or 8 bytes. The address of a chunk is always the address of its first byte.

MIPS Registers

The MIPS architecture has three sets of registers:

A useful computer system also needs an operating system. The operating system manages all system resources. Resources include

MIPS uses a single syscall instruction for all access to operating system services. The setup for a syscall instruction puts a syscall code into a register. This syscall code specifies the operating system service that is needed. It is just used as an index into a table of functions. These functions are set up by an operating system when it is booted.

This design lets MIPS work with any operating system. Usually a MIPS simulator provides only a rudimentary operating system for its simulated MIPS processor. Its services are not necessarily typical of the services provided by real operating systems.

The primary job of an assembler is to translate assembly language into machine language. Modern assemblers also simplify dealing with memory by providing directives for labeling chunks of memory. They allocate and keep track of the addresses and allow a programmer to use labels instead of addresses in assembly language code. In effect they are doing the same thing that a compiler does with variable declarations.

A MAL program is divided into two types of sections:

MAL assembly language statements are either instructions or directives. Instructions are MIPS machine instructions or pseudoinstructions specifying program runtime actions. They are almost always found in text sections.

Directives are instructions to the assembler, specifying an action to be taken during assembly. They are usually found in data sections.

This web presentation only describes directives, instructions, and registers needed for integer programming. Other web presentations at this web site give a more complete description of MIPS assembly language.

Instructions and directives both have the following form:

label  operation  operand_list # comment

The label should be a string of alphabetic and numeric characters, either upper or lower case. The assembler does distinguish between upper and lower case. When used as a line label, the label should be followed by a colon. When it appears in an operand, the colon should be omitted. When a label is not used, the line should begin with a space or tab character.

A label can appear on a line by itself, but this should only be used for instruction labels. Some assemblers cannot handle variable declarations properly if the label is on a different line.