MIPS Runtime library

Compiled programs

Compiling a C or C++ file links the Runtime library automatically. Startup aligns the stack, runs global constructors, calls main, and passes its result to exit. Build completes startup before execution begins in your code: the first instruction is in main, or in a C++ global constructor that runs before main. Undo can reverse steps from that point onward; it does not reverse startup. Streams are unbuffered by default, so stepping over printf shows its text at once. Requested output buffering delays output until a flush, a full buffer, or a newline for line buffering.

From hand-written assembly

Hand-written assembly can call the library too. In the Workbench's Settings panel, open Project Settings and set Link Runtime library to Runtime ABI v1. Then call a function with jal using the MIPS O32 calling convention:

  • Argument words are 32-bit slots. The first four slots use $a0 to $a3; a 64-bit value such as a double uses an even-numbered pair, for example $a2 and $a3. Leading floating-point arguments use $f12 and $f14 under O32. Arguments that do not fit in the registers go on the stack.
  • Reserve 16 bytes at the top of the caller's stack frame for the four argument slots, even when all arguments fit in registers. The callee may use this area to save those registers.
  • Keep $sp a multiple of 8 at the call. The program starts with $sp at 0x7fffeffc, so align it before calling. Misaligned stack access to a double can fault.
  • Integer results return in $v0 (a 64-bit result uses $v0 and $v1); floating-point results return in $f0.

The setting is off by default, so a call to a function you have not written yet still reports an undefined symbol; that message says when the function is in the library.

.data
format: .asciiz "%d + %d = %d\n"
.text
main:
    li $t0, -8
    and $sp, $sp, $t0      # align the stack to 8 bytes
    addiu $sp, $sp, -16    # the argument area printf may use
    la $a0, format
    li $a1, 2
    li $a2, 3
    li $a3, 5
    jal printf
    addiu $sp, $sp, 16
    li $v0, 10
    syscall

A program that calls the library this way keeps its own start and its own addresses: the library's code and data come after the program's. The library needs no initialization, so every function works without the startup code.

Standard input

Reading standard input (scanf, fgets, getchar) waits for a line typed in the console and keeps what the program did not read for the next call, as a terminal does. Pressing Ctrl+D, or the console's End of input button, on an empty line ends standard input: the read returns end of file. In a Testcase, standard input ends when its scripted answers run out.

Reading the library

The Explorer is the file list for the current Build. It includes linked library functions as read-only files. From a call such as jal printf, choose Go to Definition to open the function's assembly; choose Show C source to open its C implementation with matching source lines.

Stepping

By default, Step over jal printf runs the whole library call, and one Undo reverses that call. A library function that calls back into your program, such as qsort calling its comparison function, stops in your code. To inspect library instructions one at a time, turn on Step into Runtime library code in Preferences. With this enabled, stepping begins in startup code at _start.

main receives argc == 0 and a valid argv array containing one null pointer. malloc follows the compiler's max_align_t alignment and returns NULL with ENOMEM on exhaustion. clock() counts executed instructions at nominal 100 MHz and excludes waiting time; Undo rewinds that counter. time() reports calendar time, with 2000-01-01 UTC as the fixed Testcase epoch. Library calendar conversions use UTC. Input buffering requests fail; default input remains unbuffered.

_Exit

<stdlib.h>

Ends the program immediately with the given status, without running atexit handlers.

Declaration
void _Exit(int status)
Header
<stdlib.h>
From assembly
status → $a0; returns nothing
Example
jal _Exit

__assert_fail

<assert.h>

Prints "Assertion failed: expr (file: func: line)" to stderr and aborts; called by the assert macro.

Declaration
void __assert_fail(const char *expr, const char *file, int line, const char *func)
Header
<assert.h>
From assembly
expr → $a0; file → $a1; line → $a2; func → $a3; returns nothing
Example
jal __assert_fail

abort

<stdlib.h>

Ends the program abnormally with status 134, without running atexit handlers.

Declaration
void abort(void)
Header
<stdlib.h>
From assembly
returns nothing
Example
jal abort

abs

<stdlib.h>

Returns the absolute value of an int.

Declaration
int abs(int n)
Header
<stdlib.h>
From assembly
n → $a0; returns int in $v0
Example
jal abs

acos

<math.h>

Returns the arc cosine of x, in radians between 0 and pi.

Declaration
double acos(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal acos

aligned_alloc

<stdlib.h>

Allocates size bytes aligned to alignment (a power of two) and returns a pointer, or NULL.

Declaration
void *aligned_alloc(size_t alignment, size_t size)
Header
<stdlib.h>
From assembly
alignment → $a0; size → $a1; returns void * in $v0
Example
jal aligned_alloc

asctime

<time.h>

Formats *tm as "Www Mmm dd hh:mm:ss yyyy\n" in a static buffer and returns it.

Declaration
char *asctime(const struct tm *tm)
Header
<time.h>
From assembly
tm → $a0; returns char * in $v0
Example
jal asctime

asin

<math.h>

Returns the arc sine of x, in radians between -pi/2 and pi/2.

Declaration
double asin(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal asin

atan

<math.h>

Returns the arc tangent of x, in radians between -pi/2 and pi/2.

Declaration
double atan(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal atan

atan2

<math.h>

Returns the arc tangent of y/x using the signs of both to pick the quadrant, in radians between -pi and pi.

Declaration
double atan2(double y, double x)
Header
<math.h>
From assembly
y → $f12; x → $f14; returns double in $f0
Example
jal atan2

atexit

<stdlib.h>

Registers a function for exit to call, in reverse order of registration; returns 0 on success.

Declaration
int atexit(void(*func)(void))
Header
<stdlib.h>
From assembly
void(*func)(void) → $a0; returns int in $v0
Example
jal atexit

atof

<stdlib.h>

Converts the start of a string to double (no error detection).

Declaration
double atof(const char *str)
Header
<stdlib.h>
From assembly
str → $a0; returns double in $f0
Example
jal atof

atoi

<stdlib.h>

Converts the start of a string to int (decimal, no error detection).

Declaration
int atoi(const char *str)
Header
<stdlib.h>
From assembly
str → $a0; returns int in $v0
Example
jal atoi

atol

<stdlib.h>

Converts the start of a string to long (decimal, no error detection).

Declaration
long atol(const char *str)
Header
<stdlib.h>
From assembly
str → $a0; returns long in $v0
Example
jal atol

atoll

<stdlib.h>

Converts the start of a string to long long (decimal, no error detection).

Declaration
long long atoll(const char *str)
Header
<stdlib.h>
From assembly
str → $a0; returns long long in $v0:$v1
Example
jal atoll

bsearch

<stdlib.h>

Searches a sorted array for key with the comparison function cmp; returns the matching element or NULL.

Declaration
void *bsearch(const void *key, const void *base, size_t count, size_t size, int(*cmp)(const void *, const void *))
Header
<stdlib.h>
From assembly
key → $a0; base → $a1; count → $a2; size → $a3; int(cmp)(const void , const void ) → stack; returns void in $v0
Example
jal bsearch

calloc

<stdlib.h>

Allocates zeroed memory for count objects of size bytes each, or returns NULL if the total overflows or memory runs out.

Declaration
void *calloc(size_t count, size_t size)
Header
<stdlib.h>
From assembly
count → $a0; size → $a1; returns void * in $v0
Example
jal calloc

cbrt

<math.h>

Returns the cube root of x.

Declaration
double cbrt(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal cbrt

ceil

<math.h>

Returns the smallest integer value not less than x.

Declaration
double ceil(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal ceil

ceilf

<math.h>

Returns the smallest integer value not less than x (float).

Declaration
float ceilf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal ceilf

clearerr

<stdio.h>

Clears the end-of-file and error indicators of stream.

Declaration
void clearerr(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns nothing
Example
jal clearerr

clock

<time.h>

Returns processor time in CLOCKS_PER_SEC units; simulator instructions run at nominal 100 MHz. Returns -1 on overflow.

Declaration
clock_t clock(void)
Header
<time.h>
From assembly
returns clock_t in $v0
Example
jal clock

copysign

<math.h>

Returns the magnitude of x with the sign of y.

Declaration
double copysign(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal copysign

cos

<math.h>

Returns the cosine of x (radians).

Declaration
double cos(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal cos

cosf

<math.h>

Returns the cosine of x in radians (float).

Declaration
float cosf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal cosf

cosh

<math.h>

Returns the hyperbolic cosine of x.

Declaration
double cosh(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal cosh

ctime

<time.h>

Formats the time *t like asctime(localtime(t)).

Declaration
char *ctime(const time_t *t)
Header
<time.h>
From assembly
t → $a0; returns char * in $v0
Example
jal ctime

difftime

<time.h>

Returns end - start in seconds.

Declaration
double difftime(time_t end, time_t start)
Header
<time.h>
From assembly
end → $a0; start → $a1; returns double in $f0
Example
jal difftime

div

<stdlib.h>

Divides two ints, returning the quotient and remainder together.

Declaration
div_t div(int num, int den)
Header
<stdlib.h>
From assembly
num → $a0; den → $a1; returns div_t in $v0
Example
jal div

exit

<stdlib.h>

Runs atexit handlers and static destructors, then ends the program with the given status.

Declaration
void exit(int status)
Header
<stdlib.h>
From assembly
status → $a0; returns nothing
Example
jal exit

exp

<math.h>

Returns e raised to the power x.

Declaration
double exp(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal exp

expf

<math.h>

Returns e raised to the power x (float).

Declaration
float expf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal expf

expm1

<math.h>

Returns e raised to the power x, minus 1, accurately even for x near 0.

Declaration
double expm1(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal expm1

fabs

<math.h>

Returns the absolute value of x.

Declaration
double fabs(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal fabs

fabsf

<math.h>

Returns the absolute value of x (float).

Declaration
float fabsf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal fabsf

fclose

<stdio.h>

Closes a stream opened by fopen and returns 0, or EOF on error.

Declaration
int fclose(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal fclose

feof

<stdio.h>

Returns nonzero if the end-of-file indicator of stream is set.

Declaration
int feof(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal feof

ferror

<stdio.h>

Returns nonzero if the error indicator of stream is set.

Declaration
int ferror(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal ferror

fflush

<stdio.h>

Flushes pending output; NULL flushes all output streams. Returns 0, or EOF on failure.

Declaration
int fflush(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal fflush

fgetc

<stdio.h>

Reads the next character from stream as an unsigned char converted to int, or returns EOF.

Declaration
int fgetc(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal fgetc

fgetpos

<stdio.h>

Stores the current position of stream in *pos; returns 0, or -1 on error.

Declaration
int fgetpos(FILE *stream, fpos_t *pos)
Header
<stdio.h>
From assembly
stream → $a0; pos → $a1; returns int in $v0
Example
jal fgetpos

fgets

<stdio.h>

Reads a line of at most n-1 characters, keeping the newline, into str; returns str, or NULL if nothing was read.

Declaration
char *fgets(char *str, int n, FILE *stream)
Header
<stdio.h>
From assembly
str → $a0; n → $a1; stream → $a2; returns char * in $v0
Example
jal fgets

floor

<math.h>

Returns the largest integer value not greater than x.

Declaration
double floor(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal floor

floorf

<math.h>

Returns the largest integer value not greater than x (float).

Declaration
float floorf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal floorf

fmax

<math.h>

Returns the larger of x and y, ignoring a NaN argument.

Declaration
double fmax(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal fmax

fmin

<math.h>

Returns the smaller of x and y, ignoring a NaN argument.

Declaration
double fmin(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal fmin

fmod

<math.h>

Returns the remainder of x / y with the sign of x.

Declaration
double fmod(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal fmod

fmodf

<math.h>

Returns the remainder of x / y with the sign of x (float).

Declaration
float fmodf(float x, float y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns float in $f0
Example
jal fmodf

fopen

<stdio.h>

Opens the file at path with mode "r", "w" or "a" (optionally with "+", "b" or "x") and returns its stream, or NULL with errno set.

Declaration
FILE *fopen(const char *path, const char *mode)
Header
<stdio.h>
From assembly
path → $a0; mode → $a1; returns FILE * in $v0
Example
jal fopen

fprintf

<stdio.h>

Writes formatted output to stream and returns the number of bytes written, or a negative value on error.

Declaration
int fprintf(FILE *stream, const char *format, ...)
Header
<stdio.h>
From assembly
stream → $a0; format → $a1; the remaining arguments → $a2…$a3, then the stack; returns int in $v0
Example
jal fprintf

fputc

<stdio.h>

Writes the character c to stream and returns it, or EOF on error.

Declaration
int fputc(int c, FILE *stream)
Header
<stdio.h>
From assembly
c → $a0; stream → $a1; returns int in $v0
Example
jal fputc

fputs

<stdio.h>

Writes the string str to stream without a newline; returns a non-negative value, or EOF on error.

Declaration
int fputs(const char *str, FILE *stream)
Header
<stdio.h>
From assembly
str → $a0; stream → $a1; returns int in $v0
Example
jal fputs

fread

<stdio.h>

Reads up to count items of size bytes each into ptr and returns the number of complete items read.

Declaration
size_t fread(void *ptr, size_t size, size_t count, FILE *stream)
Header
<stdio.h>
From assembly
ptr → $a0; size → $a1; count → $a2; stream → $a3; returns size_t in $v0
Example
jal fread

free

<stdlib.h>

Releases a block returned by malloc, calloc, realloc or aligned_alloc; free(NULL) does nothing.

Declaration
void free(void *ptr)
Header
<stdlib.h>
From assembly
ptr → $a0; returns nothing
Example
jal free

freopen

<stdio.h>

Closes stream and opens path in its place, as fopen would; commonly used to read stdin from a File.

Declaration
FILE *freopen(const char *path, const char *mode, FILE *stream)
Header
<stdio.h>
From assembly
path → $a0; mode → $a1; stream → $a2; returns FILE * in $v0
Example
jal freopen

frexp

<math.h>

Splits x into a fraction in [0.5, 1) returned and a power of two stored in *exp.

Declaration
double frexp(double x, int *exp)
Header
<math.h>
From assembly
x → $f12; exp → $a2; returns double in $f0
Example
jal frexp

fscanf

<stdio.h>

Reads formatted input from stream and returns the number of items assigned, or EOF if input ended before the first conversion.

Declaration
int fscanf(FILE *stream, const char *format, ...)
Header
<stdio.h>
From assembly
stream → $a0; format → $a1; the remaining arguments → $a2…$a3, then the stack; returns int in $v0
Example
jal fscanf

fseek

<stdio.h>

Moves the position of stream to offset from SEEK_SET, SEEK_CUR or SEEK_END; returns 0, or -1 on error.

Declaration
int fseek(FILE *stream, long offset, int whence)
Header
<stdio.h>
From assembly
stream → $a0; offset → $a1; whence → $a2; returns int in $v0
Example
jal fseek

fsetpos

<stdio.h>

Moves stream to a position saved by fgetpos; returns 0, or -1 on error.

Declaration
int fsetpos(FILE *stream, const fpos_t *pos)
Header
<stdio.h>
From assembly
stream → $a0; pos → $a1; returns int in $v0
Example
jal fsetpos

ftell

<stdio.h>

Returns the current position of stream, or -1 on error.

Declaration
long ftell(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns long in $v0
Example
jal ftell

fwrite

<stdio.h>

Writes count items of size bytes each from ptr and returns the number of complete items written.

Declaration
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream)
Header
<stdio.h>
From assembly
ptr → $a0; size → $a1; count → $a2; stream → $a3; returns size_t in $v0
Example
jal fwrite

getc

<stdio.h>

Reads the next character from stream, exactly like fgetc.

Declaration
int getc(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns int in $v0
Example
jal getc

getchar

<stdio.h>

Reads the next character from stdin, or returns EOF at the end of input.

Declaration
int getchar(void)
Header
<stdio.h>
From assembly
returns int in $v0
Example
jal getchar

getenv

<stdlib.h>

Always returns NULL: programs have no environment.

Declaration
char *getenv(const char *name)
Header
<stdlib.h>
From assembly
name → $a0; returns char * in $v0
Example
jal getenv

gmtime

<time.h>

Breaks *t into UTC calendar fields stored in a static struct tm and returns it, or NULL on overflow.

Declaration
struct tm *gmtime(const time_t *t)
Header
<time.h>
From assembly
t → $a0; returns struct tm * in $v0
Example
jal gmtime

hypot

<math.h>

Returns sqrt(xx + yy) without undue overflow or underflow.

Declaration
double hypot(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal hypot

imaxabs

<inttypes.h>

Returns the absolute value of an intmax_t.

Declaration
intmax_t imaxabs(intmax_t n)
Header
<inttypes.h>
From assembly
n → $a0:$a1; returns intmax_t in $v0:$v1
Example
jal imaxabs

imaxdiv

<inttypes.h>

Divides two intmax_t values, returning the quotient and remainder together.

Declaration
imaxdiv_t imaxdiv(intmax_t num, intmax_t den)
Header
<inttypes.h>
From assembly
num → $a0:$a1; den → $a2:$a3; returns imaxdiv_t in $v0
Example
jal imaxdiv

isalnum

<ctype.h>

Returns nonzero if c is a letter or a digit.

Declaration
int isalnum(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isalnum

isalpha

<ctype.h>

Returns nonzero if c is a letter.

Declaration
int isalpha(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isalpha

isblank

<ctype.h>

Returns nonzero if c is a space or a tab.

Declaration
int isblank(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isblank

iscntrl

<ctype.h>

Returns nonzero if c is a control character.

Declaration
int iscntrl(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal iscntrl

isdigit

<ctype.h>

Returns nonzero if c is a decimal digit.

Declaration
int isdigit(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isdigit

isgraph

<ctype.h>

Returns nonzero if c is printable and not a space.

Declaration
int isgraph(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isgraph

islower

<ctype.h>

Returns nonzero if c is a lowercase letter.

Declaration
int islower(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal islower

isprint

<ctype.h>

Returns nonzero if c is printable, including the space.

Declaration
int isprint(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isprint

ispunct

<ctype.h>

Returns nonzero if c is printable but neither a space nor alphanumeric.

Declaration
int ispunct(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal ispunct

isspace

<ctype.h>

Returns nonzero if c is white space: space, \t, \n, \v, \f or \r.

Declaration
int isspace(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isspace

isupper

<ctype.h>

Returns nonzero if c is an uppercase letter.

Declaration
int isupper(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isupper

isxdigit

<ctype.h>

Returns nonzero if c is a hexadecimal digit.

Declaration
int isxdigit(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal isxdigit

labs

<stdlib.h>

Returns the absolute value of a long.

Declaration
long labs(long n)
Header
<stdlib.h>
From assembly
n → $a0; returns long in $v0
Example
jal labs

ldexp

<math.h>

Returns x multiplied by 2 raised to exp.

Declaration
double ldexp(double x, int exp)
Header
<math.h>
From assembly
x → $f12; exp → $a2; returns double in $f0
Example
jal ldexp

ldiv

<stdlib.h>

Divides two longs, returning the quotient and remainder together.

Declaration
ldiv_t ldiv(long num, long den)
Header
<stdlib.h>
From assembly
num → $a0; den → $a1; returns ldiv_t in $v0
Example
jal ldiv

llabs

<stdlib.h>

Returns the absolute value of a long long.

Declaration
long long llabs(long long n)
Header
<stdlib.h>
From assembly
n → $a0:$a1; returns long long in $v0:$v1
Example
jal llabs

lldiv

<stdlib.h>

Divides two long longs, returning the quotient and remainder together.

Declaration
lldiv_t lldiv(long long num, long long den)
Header
<stdlib.h>
From assembly
num → $a0:$a1; den → $a2:$a3; returns lldiv_t in $v0
Example
jal lldiv

localtime

<time.h>

Same as gmtime: programs run in UTC.

Declaration
struct tm *localtime(const time_t *t)
Header
<time.h>
From assembly
t → $a0; returns struct tm * in $v0
Example
jal localtime

log

<math.h>

Returns the natural logarithm of x.

Declaration
double log(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal log

log10

<math.h>

Returns the base-10 logarithm of x.

Declaration
double log10(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal log10

log2

<math.h>

Returns the base-2 logarithm of x.

Declaration
double log2(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal log2

logf

<math.h>

Returns the natural logarithm of x (float).

Declaration
float logf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal logf

malloc

<stdlib.h>

Allocates size bytes of uninitialized memory and returns a pointer to it, or NULL with errno set to ENOMEM.

Declaration
void *malloc(size_t size)
Header
<stdlib.h>
From assembly
size → $a0; returns void * in $v0
Example
jal malloc

memchr

<string.h>

Returns a pointer to the first byte equal to c in the first n bytes of s, or NULL.

Declaration
void *memchr(const void *s, int c, size_t n)
Header
<string.h>
From assembly
s → $a0; c → $a1; n → $a2; returns void * in $v0
Example
jal memchr

memcmp

<string.h>

Compares n bytes as unsigned chars; returns a negative, zero or positive value.

Declaration
int memcmp(const void *a, const void *b, size_t n)
Header
<string.h>
From assembly
a → $a0; b → $a1; n → $a2; returns int in $v0
Example
jal memcmp

memcpy

<string.h>

Copies n bytes from src to dest, which must not overlap, and returns dest.

Declaration
void *memcpy(void *dest, const void *src, size_t n)
Header
<string.h>
From assembly
dest → $a0; src → $a1; n → $a2; returns void * in $v0
Example
jal memcpy

memmove

<string.h>

Copies n bytes from src to dest, which may overlap, and returns dest.

Declaration
void *memmove(void *dest, const void *src, size_t n)
Header
<string.h>
From assembly
dest → $a0; src → $a1; n → $a2; returns void * in $v0
Example
jal memmove

memset

<string.h>

Fills n bytes at dest with the byte c and returns dest.

Declaration
void *memset(void *dest, int c, size_t n)
Header
<string.h>
From assembly
dest → $a0; c → $a1; n → $a2; returns void * in $v0
Example
jal memset

mktime

<time.h>

Normalizes the fields of *tm, read as UTC, and returns the matching time_t, or -1 if it cannot be represented.

Declaration
time_t mktime(struct tm *tm)
Header
<time.h>
From assembly
tm → $a0; returns time_t in $v0
Example
jal mktime

modf

<math.h>

Splits x into an integral part stored in *ip and a fractional part returned, both with the sign of x.

Declaration
double modf(double x, double *ip)
Header
<math.h>
From assembly
x → $f12; ip → $a2; returns double in $f0
Example
jal modf

perror

<stdio.h>

Writes msg, a colon and the message for the current errno to stderr.

Declaration
void perror(const char *msg)
Header
<stdio.h>
From assembly
msg → $a0; returns nothing
Example
jal perror

pow

<math.h>

Returns x raised to the power y.

Declaration
double pow(double x, double y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns double in $f0
Example
jal pow

powf

<math.h>

Returns x raised to the power y (float).

Declaration
float powf(float x, float y)
Header
<math.h>
From assembly
x → $f12; y → $f14; returns float in $f0
Example
jal powf

printf

<stdio.h>

Writes formatted output to stdout and returns the number of bytes written, or a negative value on error.

Declaration
int printf(const char *format, ...)
Header
<stdio.h>
From assembly
format → $a0; the remaining arguments → $a1…$a3, then the stack; returns int in $v0
Example
jal printf

putc

<stdio.h>

Writes the character c to stream, exactly like fputc.

Declaration
int putc(int c, FILE *stream)
Header
<stdio.h>
From assembly
c → $a0; stream → $a1; returns int in $v0
Example
jal putc

putchar

<stdio.h>

Writes the character c to stdout and returns it, or EOF on error.

Declaration
int putchar(int c)
Header
<stdio.h>
From assembly
c → $a0; returns int in $v0
Example
jal putchar

puts

<stdio.h>

Writes the string str and a newline to stdout; returns a non-negative value, or EOF on error.

Declaration
int puts(const char *str)
Header
<stdio.h>
From assembly
str → $a0; returns int in $v0
Example
jal puts

qsort

<stdlib.h>

Sorts count elements of size bytes at base in place using the comparison function cmp.

Declaration
void qsort(void *base, size_t count, size_t size, int(*cmp)(const void *, const void *))
Header
<stdlib.h>
From assembly
base → $a0; count → $a1; size → $a2; int(cmp)(const void , const void *) → $a3; returns nothing
Example
jal qsort

rand

<stdlib.h>

Returns a pseudo-random integer between 0 and RAND_MAX.

Declaration
int rand(void)
Header
<stdlib.h>
From assembly
returns int in $v0
Example
jal rand

realloc

<stdlib.h>

Resizes the block at ptr to size bytes, moving it if needed; returns the new pointer, or NULL leaving the block unchanged.

Declaration
void *realloc(void *ptr, size_t size)
Header
<stdlib.h>
From assembly
ptr → $a0; size → $a1; returns void * in $v0
Example
jal realloc

rewind

<stdio.h>

Moves stream back to its start and clears its error indicator.

Declaration
void rewind(FILE *stream)
Header
<stdio.h>
From assembly
stream → $a0; returns nothing
Example
jal rewind

round

<math.h>

Returns x rounded to the nearest integer value, halfway cases away from zero.

Declaration
double round(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal round

roundf

<math.h>

Returns x rounded to the nearest integer value, halfway cases away from zero (float).

Declaration
float roundf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal roundf

scalbn

<math.h>

Returns x multiplied by 2 raised to n.

Declaration
double scalbn(double x, int n)
Header
<math.h>
From assembly
x → $f12; n → $a2; returns double in $f0
Example
jal scalbn

scanf

<stdio.h>

Reads formatted input from stdin and returns the number of items assigned, or EOF if input ended before the first conversion.

Declaration
int scanf(const char *format, ...)
Header
<stdio.h>
From assembly
format → $a0; the remaining arguments → $a1…$a3, then the stack; returns int in $v0
Example
jal scanf

setbuf

<stdio.h>

Requests full output buffering with BUFSIZ bytes, or unbuffered output when buf is NULL.

Declaration
void setbuf(FILE *stream, char *buf)
Header
<stdio.h>
From assembly
stream → $a0; buf → $a1; returns nothing
Example
jal setbuf

setvbuf

<stdio.h>

Sets output buffering (_IOFBF, _IOLBF or _IONBF); input buffering is unsupported. Returns 0, or nonzero on failure.

Declaration
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
Header
<stdio.h>
From assembly
stream → $a0; buf → $a1; mode → $a2; size → $a3; returns int in $v0
Example
jal setvbuf

sin

<math.h>

Returns the sine of x (radians).

Declaration
double sin(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal sin

sincos

<math.h>

Stores the sine and cosine of x (radians) in *s and *c (GNU extension; GCC may combine sin and cos calls into it).

Declaration
void sincos(double x, double *s, double *c)
Header
<math.h>
From assembly
x → $f12; s → $a2; c → $a3; returns nothing
Example
jal sincos

sincosf

<math.h>

Stores the sine and cosine of x in radians in *s and *c (float, GNU extension).

Declaration
void sincosf(float x, float *s, float *c)
Header
<math.h>
From assembly
x → $f12; s → $a1; c → $a2; returns nothing
Example
jal sincosf

sinf

<math.h>

Returns the sine of x in radians (float).

Declaration
float sinf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal sinf

sinh

<math.h>

Returns the hyperbolic sine of x.

Declaration
double sinh(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal sinh

snprintf

<stdio.h>

Writes at most n-1 formatted characters into str plus a NUL and returns the length the full output would have had.

Declaration
int snprintf(char *str, size_t n, const char *format, ...)
Header
<stdio.h>
From assembly
str → $a0; n → $a1; format → $a2; the remaining arguments → $a3…$a3, then the stack; returns int in $v0
Example
jal snprintf

sprintf

<stdio.h>

Writes formatted output into str with a terminating NUL and returns the number of characters written.

Declaration
int sprintf(char *str, const char *format, ...)
Header
<stdio.h>
From assembly
str → $a0; format → $a1; the remaining arguments → $a2…$a3, then the stack; returns int in $v0
Example
jal sprintf

sqrt

<math.h>

Returns the square root of x, correctly rounded.

Declaration
double sqrt(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal sqrt

sqrtf

<math.h>

Returns the square root of x, correctly rounded (float).

Declaration
float sqrtf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal sqrtf

srand

<stdlib.h>

Seeds the sequence returned by rand; the same seed repeats the same sequence.

Declaration
void srand(unsigned int seed)
Header
<stdlib.h>
From assembly
seed → $a0; returns nothing
Example
jal srand

sscanf

<stdio.h>

Reads formatted input from the string str and returns the number of items assigned.

Declaration
int sscanf(const char *str, const char *format, ...)
Header
<stdio.h>
From assembly
str → $a0; format → $a1; the remaining arguments → $a2…$a3, then the stack; returns int in $v0
Example
jal sscanf

strcat

<string.h>

Appends the string src to the end of dest and returns dest.

Declaration
char *strcat(char *dest, const char *src)
Header
<string.h>
From assembly
dest → $a0; src → $a1; returns char * in $v0
Example
jal strcat

strchr

<string.h>

Returns a pointer to the first occurrence of the character c in s (c may be NUL), or NULL.

Declaration
char *strchr(const char *s, int c)
Header
<string.h>
From assembly
s → $a0; c → $a1; returns char * in $v0
Example
jal strchr

strcmp

<string.h>

Compares two strings; returns a negative, zero or positive value.

Declaration
int strcmp(const char *a, const char *b)
Header
<string.h>
From assembly
a → $a0; b → $a1; returns int in $v0
Example
jal strcmp

strcoll

<string.h>

Compares two strings in the "C" locale, exactly like strcmp.

Declaration
int strcoll(const char *a, const char *b)
Header
<string.h>
From assembly
a → $a0; b → $a1; returns int in $v0
Example
jal strcoll

strcpy

<string.h>

Copies the string src, including its NUL, to dest and returns dest.

Declaration
char *strcpy(char *dest, const char *src)
Header
<string.h>
From assembly
dest → $a0; src → $a1; returns char * in $v0
Example
jal strcpy

strcspn

<string.h>

Returns the length of the initial part of s containing no character from reject.

Declaration
size_t strcspn(const char *s, const char *reject)
Header
<string.h>
From assembly
s → $a0; reject → $a1; returns size_t in $v0
Example
jal strcspn

strdup

<string.h>

Returns a malloc'ed copy of the string s, or NULL if memory runs out.

Declaration
char *strdup(const char *s)
Header
<string.h>
From assembly
s → $a0; returns char * in $v0
Example
jal strdup

strerror

<string.h>

Returns a message describing the error number errnum.

Declaration
char *strerror(int errnum)
Header
<string.h>
From assembly
errnum → $a0; returns char * in $v0
Example
jal strerror

strlen

<string.h>

Returns the length of the string s, not counting its terminating NUL.

Declaration
size_t strlen(const char *s)
Header
<string.h>
From assembly
s → $a0; returns size_t in $v0
Example
jal strlen

strncat

<string.h>

Appends at most n characters of src, then a NUL, to dest and returns dest.

Declaration
char *strncat(char *dest, const char *src, size_t n)
Header
<string.h>
From assembly
dest → $a0; src → $a1; n → $a2; returns char * in $v0
Example
jal strncat

strncmp

<string.h>

Compares at most n characters of two strings; returns a negative, zero or positive value.

Declaration
int strncmp(const char *a, const char *b, size_t n)
Header
<string.h>
From assembly
a → $a0; b → $a1; n → $a2; returns int in $v0
Example
jal strncmp

strncpy

<string.h>

Copies at most n characters of src to dest, padding with NULs; dest is not terminated if src is n or longer. Returns dest.

Declaration
char *strncpy(char *dest, const char *src, size_t n)
Header
<string.h>
From assembly
dest → $a0; src → $a1; n → $a2; returns char * in $v0
Example
jal strncpy

strndup

<string.h>

Returns a malloc'ed copy of at most n characters of s, always terminated, or NULL if memory runs out.

Declaration
char *strndup(const char *s, size_t n)
Header
<string.h>
From assembly
s → $a0; n → $a1; returns char * in $v0
Example
jal strndup

strnlen

<string.h>

Returns the length of s, but at most n.

Declaration
size_t strnlen(const char *s, size_t n)
Header
<string.h>
From assembly
s → $a0; n → $a1; returns size_t in $v0
Example
jal strnlen

strpbrk

<string.h>

Returns a pointer to the first character of s that is in accept, or NULL.

Declaration
char *strpbrk(const char *s, const char *accept)
Header
<string.h>
From assembly
s → $a0; accept → $a1; returns char * in $v0
Example
jal strpbrk

strrchr

<string.h>

Returns a pointer to the last occurrence of the character c in s, or NULL.

Declaration
char *strrchr(const char *s, int c)
Header
<string.h>
From assembly
s → $a0; c → $a1; returns char * in $v0
Example
jal strrchr

strspn

<string.h>

Returns the length of the initial part of s made only of characters in accept.

Declaration
size_t strspn(const char *s, const char *accept)
Header
<string.h>
From assembly
s → $a0; accept → $a1; returns size_t in $v0
Example
jal strspn

strstr

<string.h>

Returns a pointer to the first occurrence of the string needle in haystack, or NULL.

Declaration
char *strstr(const char *haystack, const char *needle)
Header
<string.h>
From assembly
haystack → $a0; needle → $a1; returns char * in $v0
Example
jal strstr

strtod

<stdlib.h>

Converts the start of a string to double, correctly rounded, storing the end in *end; sets errno to ERANGE on overflow or underflow.

Declaration
double strtod(const char *str, char * *end)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; returns double in $f0
Example
jal strtod

strtof

<stdlib.h>

Converts the start of a string to float, correctly rounded, storing the end in *end; sets errno to ERANGE on overflow or underflow.

Declaration
float strtof(const char *str, char * *end)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; returns float in $f0
Example
jal strtof

strtoimax

<inttypes.h>

Converts the start of a string to intmax_t in the given base (0 detects 0x and 0 prefixes), storing the end in *end.

Declaration
intmax_t strtoimax(const char *str, char * *end, int base)
Header
<inttypes.h>
From assembly
str → $a0; end → $a1; base → $a2; returns intmax_t in $v0:$v1
Example
jal strtoimax

strtok

<string.h>

Splits a string into tokens separated by characters in delim; pass the string first, then NULL to continue.

Declaration
char *strtok(char *str, const char *delim)
Header
<string.h>
From assembly
str → $a0; delim → $a1; returns char * in $v0
Example
jal strtok

strtol

<stdlib.h>

Converts the start of a string to long in the given base (0 detects 0x and 0 prefixes), storing the end in *end; sets errno to ERANGE on overflow.

Declaration
long strtol(const char *str, char * *end, int base)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; base → $a2; returns long in $v0
Example
jal strtol

strtoll

<stdlib.h>

Converts the start of a string to long long in the given base, storing the end in *end; sets errno to ERANGE on overflow.

Declaration
long long strtoll(const char *str, char * *end, int base)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; base → $a2; returns long long in $v0:$v1
Example
jal strtoll

strtoul

<stdlib.h>

Converts the start of a string to unsigned long in the given base, storing the end in *end; sets errno to ERANGE on overflow.

Declaration
unsigned long strtoul(const char *str, char * *end, int base)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; base → $a2; returns unsigned long in $v0
Example
jal strtoul

strtoull

<stdlib.h>

Converts the start of a string to unsigned long long in the given base, storing the end in *end; sets errno to ERANGE on overflow.

Declaration
unsigned long long strtoull(const char *str, char * *end, int base)
Header
<stdlib.h>
From assembly
str → $a0; end → $a1; base → $a2; returns unsigned long long in $v0:$v1
Example
jal strtoull

strtoumax

<inttypes.h>

Converts the start of a string to uintmax_t in the given base (0 detects 0x and 0 prefixes), storing the end in *end.

Declaration
uintmax_t strtoumax(const char *str, char * *end, int base)
Header
<inttypes.h>
From assembly
str → $a0; end → $a1; base → $a2; returns uintmax_t in $v0:$v1
Example
jal strtoumax

strxfrm

<string.h>

Copies src into dest (at most n bytes) in the "C" locale and returns the length of src.

Declaration
size_t strxfrm(char *dest, const char *src, size_t n)
Header
<string.h>
From assembly
dest → $a0; src → $a1; n → $a2; returns size_t in $v0
Example
jal strxfrm

tan

<math.h>

Returns the tangent of x (radians).

Declaration
double tan(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal tan

tanf

<math.h>

Returns the tangent of x in radians (float).

Declaration
float tanf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal tanf

tanh

<math.h>

Returns the hyperbolic tangent of x.

Declaration
double tanh(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal tanh

time

<time.h>

Returns the current time in seconds since 1970-01-01 UTC and also stores it in *t when t is not NULL.

Declaration
time_t time(time_t *t)
Header
<time.h>
From assembly
t → $a0; returns time_t in $v0
Example
jal time

tolower

<ctype.h>

Returns the lowercase form of c if it is an uppercase letter, otherwise c.

Declaration
int tolower(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal tolower

toupper

<ctype.h>

Returns the uppercase form of c if it is a lowercase letter, otherwise c.

Declaration
int toupper(int c)
Header
<ctype.h>
From assembly
c → $a0; returns int in $v0
Example
jal toupper

trunc

<math.h>

Returns x rounded toward zero to an integer value.

Declaration
double trunc(double x)
Header
<math.h>
From assembly
x → $f12; returns double in $f0
Example
jal trunc

truncf

<math.h>

Returns x rounded toward zero to an integer value (float).

Declaration
float truncf(float x)
Header
<math.h>
From assembly
x → $f12; returns float in $f0
Example
jal truncf

ungetc

<stdio.h>

Pushes the character c back onto stream so the next read returns it; returns c, or EOF on failure.

Declaration
int ungetc(int c, FILE *stream)
Header
<stdio.h>
From assembly
c → $a0; stream → $a1; returns int in $v0
Example
jal ungetc

vfprintf

<stdio.h>

Like fprintf, with the arguments taken from a va_list.

Declaration
int vfprintf(FILE *stream, const char *format, va_list ap)
Header
<stdio.h>
From assembly
stream → $a0; format → $a1; ap → $a2; returns int in $v0
Example
jal vfprintf

vfscanf

<stdio.h>

Like fscanf, with the arguments taken from a va_list.

Declaration
int vfscanf(FILE *stream, const char *format, va_list ap)
Header
<stdio.h>
From assembly
stream → $a0; format → $a1; ap → $a2; returns int in $v0
Example
jal vfscanf

vprintf

<stdio.h>

Like printf, with the arguments taken from a va_list.

Declaration
int vprintf(const char *format, va_list ap)
Header
<stdio.h>
From assembly
format → $a0; ap → $a1; returns int in $v0
Example
jal vprintf

vscanf

<stdio.h>

Like scanf, with the arguments taken from a va_list.

Declaration
int vscanf(const char *format, va_list ap)
Header
<stdio.h>
From assembly
format → $a0; ap → $a1; returns int in $v0
Example
jal vscanf

vsnprintf

<stdio.h>

Like snprintf, with the arguments taken from a va_list.

Declaration
int vsnprintf(char *str, size_t n, const char *format, va_list ap)
Header
<stdio.h>
From assembly
str → $a0; n → $a1; format → $a2; ap → $a3; returns int in $v0
Example
jal vsnprintf

vsprintf

<stdio.h>

Like sprintf, with the arguments taken from a va_list.

Declaration
int vsprintf(char *str, const char *format, va_list ap)
Header
<stdio.h>
From assembly
str → $a0; format → $a1; ap → $a2; returns int in $v0
Example
jal vsprintf

vsscanf

<stdio.h>

Like sscanf, with the arguments taken from a va_list.

Declaration
int vsscanf(const char *str, const char *format, va_list ap)
Header
<stdio.h>
From assembly
str → $a0; format → $a1; ap → $a2; returns int in $v0
Example
jal vsscanf