MIPS directives

MIPS directives are used to define the structure of the program. They are not instructions that are executed by the CPU, but rather instructions that are used by the assembler to define the structure of the program.

.data

Declares a section for storing initialized data, such as variables.

.text

Declares a section for storing executable instructions. This is where program logic is written.

.kdata

Declares a section for storing kernel-mode initialized data.

.ktext

Declares a section for storing kernel-mode executable instructions.

.word

Allocates one or more 32-bit (4-byte) words in memory.

Example:

values: .word 1, 2, 3, 4

.half

Allocates one or more 16-bit (2-byte) halfwords in memory.

Example:

values: .half 1234, 5678

.byte

Allocates one or more 8-bit (1-byte) values in memory.

Example:

flags: .byte 0, 1, 1, 0

.float

Allocates a single-precision floating-point (32-bit) number in memory.

.double

Allocates a double-precision floating-point (64-bit) number in memory.

.asciiz

Stores a null-terminated string (C-style string).

Example:

message: .asciiz "Hello, world!"

.ascii

Stores a string without a null terminator. Useful when manually handling string length.

.space

Reserves a specified number of bytes in memory without initializing them.

Example:

buffer: .space 100   # Reserves 100 bytes

.align

Aligns the next data to a 2^n-byte boundary.

Example:

.align 2   # Aligns to a 4-byte boundary

.globl

Marks a symbol as global, making it accessible from other files.

Example:

.globl main   # Makes 'main' visible to the linker

.extern

Declares a symbol that is defined in another file, specifying its size.

.macro

Defines a macro, which allows writing reusable code blocks.

.end_macro

Ends a macro definition.

.include

Includes an external assembly file.

Example:

.include "myfile.s"

.eqv

Defines a symbolic constant, similar to #define in C.

Example:

.eqv SIZE 10

.set

Configures assembler settings, such as allowing modifications to the $at register.

Example:

.set noat  # Allows use of register $at

.bss

Declares an uninitialized data section, typically used for reserving large blocks of memory.

.frame

Describes a function's stack frame for the debugger: base register, stack size and return register. MARS accepts it and does nothing with it, so that compiler output assembles unchanged.

.ent

Marks the start of a function for the debugger. MARS accepts it and does nothing with it, so that compiler output assembles unchanged.

.end

Marks the end of a function for the debugger. MARS accepts it and does nothing with it, so that compiler output assembles unchanged.

.local

Marks a symbol as local to this file for the linker. MARS accepts it and does nothing with it, so that compiler output assembles unchanged.

.section

Switches to the named section. A read-only or zeroed section becomes part of the data segment here.

Example:

.section .rodata

.rdata

Declares a section for read-only initialized data, such as string literals. Read-only data is not stored separately in this simulator, so it joins the data segment.

.sdata

Alias for .rdata.

.sbss

Alias for .bss.

.comm

Reserves bytes for an uninitialized global variable, the way a C compiler declares one. Takes a symbol, a size in bytes and an optional alignment, and leaves the current section unchanged.

Example:

.comm total, 4, 4

.lcomm

Like .comm, but for a symbol local to this file, as a C compiler declares an uninitialized static variable.

.zero

Reserves the given number of bytes, which read as zero. Alias for .space.

.p2align

Alias for .align: aligns the next item on a 2^n byte boundary.

.balign

Aligns the next item on the given byte boundary, written directly rather than as a power of two.

Example:

.balign 8

.2byte

Alias for .half.

.4byte

Alias for .word.

.asciz

Alias for .asciiz: stores a null-terminated string.

.string

Alias for .asciiz: stores a null-terminated string.

.global

Alias for .globl.