RISC-V Runtime library

Compiled programs

Compiling a C or C++ file links the Runtime library automatically. Startup 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. For ordinary fixed-argument calls, integer and pointer arguments use a0 to a7, and floating-point arguments use fa0 to fa7; each register sequence is assigned independently. Arguments that do not fit in registers go on the stack. Variadic arguments (the arguments represented by ..., as in printf) use the integer argument registers and then the stack, including floating-point values. Integer or pointer results return in a0; floating-point results return in fa0. Follow the RISC-V psABI for aggregate arguments and other special cases. The setting is off by default, so an unresolved call can still report an undefined symbol; the diagnostic identifies names supplied by the library.

.data
format: .string "%d + %d = %d\n"
.text
main:
    la a0, format
    li a1, 2
    li a2, 3
    li a3, 5
    call printf
    li a7, 10
    ecall

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 call 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 call 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
call _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
call __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
call 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 a0
Example
call 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 → fa0; returns double in fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 → fa0; returns double in fa0
Example
call 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 → fa0; returns double in fa0
Example
call 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 → fa0; x → fa1; returns double in fa0
Example
call 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 a0
Example
call 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 fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 ) → a4; returns void in a0
Example
call 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 a0
Example
call calloc

cbrt

<math.h>

Returns the cube root of x.

Declaration
double cbrt(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call cbrt

ceil

<math.h>

Returns the smallest integer value not less than x.

Declaration
double ceil(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 → fa0; returns float in fa0
Example
call 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
call 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 a0
Example
call 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 → fa0; y → fa1; returns double in fa0
Example
call copysign

cos

<math.h>

Returns the cosine of x (radians).

Declaration
double cos(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call cos

cosf

<math.h>

Returns the cosine of x in radians (float).

Declaration
float cosf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call cosf

cosh

<math.h>

Returns the hyperbolic cosine of x.

Declaration
double cosh(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 a0
Example
call 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 fa0
Example
call 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 a0
Example
call 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
call exit

exp

<math.h>

Returns e raised to the power x.

Declaration
double exp(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call exp

expf

<math.h>

Returns e raised to the power x (float).

Declaration
float expf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call 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 → fa0; returns double in fa0
Example
call expm1

fabs

<math.h>

Returns the absolute value of x.

Declaration
double fabs(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call fabs

fabsf

<math.h>

Returns the absolute value of x (float).

Declaration
float fabsf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call fgets

floor

<math.h>

Returns the largest integer value not greater than x.

Declaration
double floor(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 → fa0; returns float in fa0
Example
call 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 → fa0; y → fa1; returns double in fa0
Example
call 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 → fa0; y → fa1; returns double in fa0
Example
call 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 → fa0; y → fa1; returns double in fa0
Example
call 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 → fa0; y → fa1; returns float in fa0
Example
call 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 a0
Example
call 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…a7, then the stack; returns int in a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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
call 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 a0
Example
call 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 → fa0; exp → a0; returns double in fa0
Example
call 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…a7, then the stack; returns int in a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 → fa0; y → fa1; returns double in fa0
Example
call 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; returns intmax_t in a0
Example
call 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; den → a1; returns imaxdiv_t in a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 → fa0; exp → a0; returns double in fa0
Example
call 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 a0
Example
call 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; returns long long in a0
Example
call 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; den → a1; returns lldiv_t in a0
Example
call 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 a0
Example
call localtime

log

<math.h>

Returns the natural logarithm of x.

Declaration
double log(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call log

log10

<math.h>

Returns the base-10 logarithm of x.

Declaration
double log10(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call log10

log2

<math.h>

Returns the base-2 logarithm of x.

Declaration
double log2(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call log2

logf

<math.h>

Returns the natural logarithm of x (float).

Declaration
float logf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 → fa0; ip → a0; returns double in fa0
Example
call 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
call perror

pow

<math.h>

Returns x raised to the power y.

Declaration
double pow(double x, double y)
Header
<math.h>
From assembly
x → fa0; y → fa1; returns double in fa0
Example
call 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 → fa0; y → fa1; returns float in fa0
Example
call 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…a7, then the stack; returns int in a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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
call 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 a0
Example
call 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 a0
Example
call 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
call 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 → fa0; returns double in fa0
Example
call 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 → fa0; returns float in fa0
Example
call 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 → fa0; n → a0; returns double in fa0
Example
call 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…a7, then the stack; returns int in a0
Example
call 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
call 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 a0
Example
call setvbuf

sin

<math.h>

Returns the sine of x (radians).

Declaration
double sin(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 → fa0; s → a0; c → a1; returns nothing
Example
call 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 → fa0; s → a0; c → a1; returns nothing
Example
call sincosf

sinf

<math.h>

Returns the sine of x in radians (float).

Declaration
float sinf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call sinf

sinh

<math.h>

Returns the hyperbolic sine of x.

Declaration
double sinh(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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…a7, then the stack; returns int in a0
Example
call 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…a7, then the stack; returns int in a0
Example
call sprintf

sqrt

<math.h>

Returns the square root of x, correctly rounded.

Declaration
double sqrt(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call sqrt

sqrtf

<math.h>

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

Declaration
float sqrtf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call 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
call 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…a7, then the stack; returns int in a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 fa0
Example
call 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 fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call strxfrm

tan

<math.h>

Returns the tangent of x (radians).

Declaration
double tan(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call tan

tanf

<math.h>

Returns the tangent of x in radians (float).

Declaration
float tanf(float x)
Header
<math.h>
From assembly
x → fa0; returns float in fa0
Example
call tanf

tanh

<math.h>

Returns the hyperbolic tangent of x.

Declaration
double tanh(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call toupper

trunc

<math.h>

Returns x rounded toward zero to an integer value.

Declaration
double trunc(double x)
Header
<math.h>
From assembly
x → fa0; returns double in fa0
Example
call 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 → fa0; returns float in fa0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call 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 a0
Example
call vsscanf