NASM Coding: Basics - Examples

More info on the

read()
syscall in C:

Name:
read()
System call or function: System call Links: Online Manual | Course Packet
What it does: reads data from a file into an array, and returns the # of read bytes.
What libraries you must include:
#include <unistd.h> // Defines read() and the size_t, ssize_t types.
Syntax:
ssize_t read (int fd, void *buf, size_t len); // ssize_t = signed size_t
Description of arguments:
fd
: file descriptor of an open file
buf
: The array name (or address of a variable, e.g., &var) into which data is read.
len
: Maximum number of bytes we can or wish read.
What type it returns:
ssize_t
On success: A non-negative integer indicating how many bytes we read in. This number will be equal to or smaller than
len
, and could also be
0
(end-of-file case.)
On failure:
-1
Quick example:
ssize_t number_of_chars_read_in = read (fd, arr, 100);