NASM Coding: Basics - Examples

More info on the

write()
syscall in C (this is not required for NASM programming: this is for your information only.)

Name:
write()
System call or function: System call Links: Online Manual | Course Packet
What it does: writes data from an array into a file, and returns the # of written bytes.
What libraries you must include:
#include <unistd.h> // Defines write() and the size_t, ssize_t types.
Syntax:
ssize_t write (int fd, const void *buf, size_t count);
Description of arguments:
fd
: file descriptor of a file that was open for writing
buf
: The array name (or address of a variable, e.g., &var) from which data is taken.
count
: Number of bytes we wish to write into the file.
What type it returns:
ssize_t
On success: A non-negative integer indicating how many bytes we wrote. This number will be equal to or smaller than
count
, and could also be
0
(in cases of some special files.)
On failure:
-1
Quick example:
ssize_t number_of_chars_written = write (fd, arr, strlen(arr));