# RISC-V Syscalls

[RISC-V Documentation](https://asm-editor.specy.app/documentation/risc-v.md)

Web page: https://asm-editor.specy.app/documentation/risc-v/syscall

RARS simulator services selected by the number in `a7`, with arguments and results in the registers listed for each service.

51 entries, each with its own page of markdown:

- [Making a syscall](https://asm-editor.specy.app/documentation/risc-v/syscall/making-a-syscall.md): An ecall asks the simulator to provide a service such as printing text, reading input, reading calendar time, or working with a file.
- [Files and folders](https://asm-editor.specy.app/documentation/risc-v/syscall/folders.md): File services read and change the files shown in the editor's file explorer.
- [Sound](https://asm-editor.specy.app/documentation/risc-v/syscall/sound.md): Services 31 and 33 play a note with a pitch, instrument, volume, and duration in milliseconds.
- [Program arguments](https://asm-editor.specy.app/documentation/risc-v/syscall/arguments.md): Enter Arguments on the Terminal's first line, the Command line, or in the project's Settings panel.
- [Print integer](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1.md) `a7 = 1`: Takes a0, integer to print.
- [Print float](https://asm-editor.specy.app/documentation/risc-v/syscall/service-2.md) `a7 = 2`: Takes fa0, float to print.
- [Print double](https://asm-editor.specy.app/documentation/risc-v/syscall/service-3.md) `a7 = 3`: Takes fa0, double to print.
- [Print string](https://asm-editor.specy.app/documentation/risc-v/syscall/service-4.md) `a7 = 4`: Takes a0, address of NUL-terminated UTF-8 string to print.
- [Read integer](https://asm-editor.specy.app/documentation/risc-v/syscall/service-5.md) `a7 = 5`: Returns a0, contains the integer parsed from the input line.
- [Read float](https://asm-editor.specy.app/documentation/risc-v/syscall/service-6.md) `a7 = 6`: Returns fa0, contains the floating-point value parsed from the input line.
- [Read double](https://asm-editor.specy.app/documentation/risc-v/syscall/service-7.md) `a7 = 7`: Returns fa0, contains the double-precision value parsed from the input line.
- [Read string](https://asm-editor.specy.app/documentation/risc-v/syscall/service-8.md) `a7 = 8`: Takes a0, address of input buffer; a1, size of input buffer in bytes.
- [Sbrk (allocate heap memory)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-9.md) `a7 = 9`: Takes a0, number of bytes to allocate.
- [Exit (terminate execution)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-10.md) `a7 = 10`: Ends the program successfully with exit code 0.
- [Print character](https://asm-editor.specy.app/documentation/risc-v/syscall/service-11.md) `a7 = 11`: Takes a0, character to print.
- [Read character](https://asm-editor.specy.app/documentation/risc-v/syscall/service-12.md) `a7 = 12`: Returns a0, contains the input character code.
- [Get cwd](https://asm-editor.specy.app/documentation/risc-v/syscall/service-17.md) `a7 = 17`: Takes a0, address of the buffer to write the path into; a1, length of the buffer.
- [Time (program time)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-30.md) `a7 = 30`: Returns a0, low order 32 bits of the program time; a1, high order 32 bits of the program time.
- [MIDI out](https://asm-editor.specy.app/documentation/risc-v/syscall/service-31.md) `a7 = 31`: Takes a0, pitch, 0 to 127: 60 is middle C, 62 is D, 64 is E; each step is one semitone; a1, duration in milliseconds; a2, instrument sound from the General…
- [Sleep](https://asm-editor.specy.app/documentation/risc-v/syscall/service-32.md) `a7 = 32`: Takes a0, the length of time to sleep in milliseconds.
- [MIDI out synchronous](https://asm-editor.specy.app/documentation/risc-v/syscall/service-33.md) `a7 = 33`: Takes a0, pitch, 0 to 127: 60 is middle C, 62 is D, 64 is E; each step is one semitone; a1, duration in milliseconds; a2, instrument sound from the General…
- [Print integer in hexadecimal](https://asm-editor.specy.app/documentation/risc-v/syscall/service-34.md) `a7 = 34`: Takes a0, integer to print.
- [Print integer in binary](https://asm-editor.specy.app/documentation/risc-v/syscall/service-35.md) `a7 = 35`: Takes a0, integer to print.
- [Print integer as unsigned](https://asm-editor.specy.app/documentation/risc-v/syscall/service-36.md) `a7 = 36`: Takes a0, integer to print.
- [Set seed](https://asm-editor.specy.app/documentation/risc-v/syscall/service-40.md) `a7 = 40`: Takes a0, generator ID: any integer selects an independent pseudorandom sequence; a1, seed for corresponding pseudorandom number generator.
- [Random int](https://asm-editor.specy.app/documentation/risc-v/syscall/service-41.md) `a7 = 41`: Takes a0, generator ID: any integer selects an independent pseudorandom sequence.
- [Random int range](https://asm-editor.specy.app/documentation/risc-v/syscall/service-42.md) `a7 = 42`: Takes a0, generator ID: any integer selects an independent pseudorandom sequence; a1, upper bound of range of returned values.
- [Random float](https://asm-editor.specy.app/documentation/risc-v/syscall/service-43.md) `a7 = 43`: Takes a0, generator ID: any integer selects an independent pseudorandom sequence.
- [Random double](https://asm-editor.specy.app/documentation/risc-v/syscall/service-44.md) `a7 = 44`: Takes a0, generator ID: any integer selects an independent pseudorandom sequence.
- [ConfirmDialog](https://asm-editor.specy.app/documentation/risc-v/syscall/service-50.md) `a7 = 50`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user.
- [InputDialogInt](https://asm-editor.specy.app/documentation/risc-v/syscall/service-51.md) `a7 = 51`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user.
- [InputDialogFloat](https://asm-editor.specy.app/documentation/risc-v/syscall/service-52.md) `a7 = 52`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user.
- [InputDialogDouble](https://asm-editor.specy.app/documentation/risc-v/syscall/service-53.md) `a7 = 53`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user.
- [InputDialogString](https://asm-editor.specy.app/documentation/risc-v/syscall/service-54.md) `a7 = 54`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user; a1, address of input buffer; a2, size of input buffer in bytes.
- [MessageDialog](https://asm-editor.specy.app/documentation/risc-v/syscall/service-55.md) `a7 = 55`: Takes a0, address of NUL-terminated UTF-8 string that is the message to user; a1, the type of message to be displayed: 0: error message, indicated by Error…
- [MessageDialogInt](https://asm-editor.specy.app/documentation/risc-v/syscall/service-56.md) `a7 = 56`: Takes a0, address of NUL-terminated UTF-8 string that is an information-type message to user; a1, int value to display in string form after the first string.
- [Close file](https://asm-editor.specy.app/documentation/risc-v/syscall/service-57.md) `a7 = 57`: Takes a0, file or folder descriptor to close.
- [MessageDialogDouble](https://asm-editor.specy.app/documentation/risc-v/syscall/service-58.md) `a7 = 58`: Takes a0, address of NUL-terminated UTF-8 string that is an information-type message to user; fa0, double value to display in string form after the first…
- [MessageDialogString](https://asm-editor.specy.app/documentation/risc-v/syscall/service-59.md) `a7 = 59`: Takes a0, address of NUL-terminated UTF-8 string that is an information-type message to user; a1, address of NUL-terminated UTF-8 string to display after the…
- [MessageDialogFloat](https://asm-editor.specy.app/documentation/risc-v/syscall/service-60.md) `a7 = 60`: Takes a0, address of NUL-terminated UTF-8 string that is an information-type message to user; fa1, float value to display in string form after the first string.
- [Lseek (move file position)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-62.md) `a7 = 62`: Takes a0, file descriptor; a1, offset in bytes; a2, where the offset counts from: 0 the start of the file, 1 the current position, 2 the end of the file.
- [Read from file](https://asm-editor.specy.app/documentation/risc-v/syscall/service-63.md) `a7 = 63`: Takes a0, file descriptor; a1, address of the buffer to fill; a2, maximum number of bytes to read.
- [Write to file](https://asm-editor.specy.app/documentation/risc-v/syscall/service-64.md) `a7 = 64`: Takes a0, file descriptor; a1, address of the bytes to write; a2, number of bytes to write.
- [Exit2 (terminate with value)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-93.md) `a7 = 93`: Takes a0, termination result.
- [Open file](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1024.md) `a7 = 1024`: Takes a0, address of NUL-terminated UTF-8 path; a1, flags; a2, mode (ignored, pass 0).
- [Unlink (delete a file)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1026.md) `a7 = 1026`: Takes a0, address of NUL-terminated UTF-8 path of the file to delete.
- [Mkdir (make a folder)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1030.md) `a7 = 1030`: Takes a0, address of NUL-terminated UTF-8 path of the new folder.
- [Rmdir (delete an empty folder)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1031.md) `a7 = 1031`: Takes a0, address of NUL-terminated UTF-8 path of the folder to delete.
- [Rename (rename or move a file)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1034.md) `a7 = 1034`: Takes a0, address of NUL-terminated UTF-8 path of the file; a1, address of the NUL-terminated UTF-8 destination path.
- [Stat (describe a path)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1038.md) `a7 = 1038`: Takes a0, address of NUL-terminated UTF-8 path; a1, address of a buffer of 104 bytes in RV32 and 128 in RV64, which the service fills.
- [Getdents (list a folder)](https://asm-editor.specy.app/documentation/risc-v/syscall/service-1065.md) `a7 = 1065`: Takes a0, file descriptor of a folder, opened with service 1024 and flag 0; a1, address of the buffer to fill; a2, size of the buffer in bytes.
