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.

.org

Sets the location counter to a specific address, controlling where subsequent data or code is placed.

.ltorg

Forces the assembler to place literal pools (constants) at the current location.

..frame

Defines a function's stack frame structure, including base register, stack size, and return register.

.ent

Marks the start of a function for debugging or profiling purposes.

.end

Marks the end of an assembly file or function.

.local

Declares a symbol as local, meaning it is only accessible within the current file.