Input And Output

Top  Previous  Next

Everything XPL0 can do is useless without a way to communicate with the outside world. Input and output (I/O) is done through intrinsics, most of which call I/O device drivers in DOS or BIOS.

 

The fundamental I/O intrinsics are:

 

        variable:= ChIn(device) Input a byte (or character) from device

        ChOut(device, byte)     Output a byte to the device

        OpenI(device)           Make the device ready for input

        OpenO(device)           Make the device ready for output

        Close(device)           Close the device (flush output buffer)

 

An input device, such as the keyboard, sends bytes (or characters) that are read in by ChIn. Each time ChIn is called, it returns with the next byte. An output device, such as the monitor, receives bytes (or characters) that are sent by ChOut. ChOut sends a single byte each time it is called. Some devices must be made ready, or "opened", before they can be used. For instance, a disk file has pointers that indicate where to start filling or emptying its buffer, and these pointers must be set to the beginning of the buffer. Bytes sent to an output file pass through an output buffer, and after the last byte has been sent, this buffer is "closed" so that any bytes remaining in it are written to the disk.

 

There are other intrinsics that use the fundamental capabilities provided by ChIn and ChOut to input and output integers and reals. For example:

 

        variable:= IntIn(device)        Input an integer

        IntOut(device,expression)       Output an integer

        variable:= RlIn(device)         Input a real

        RlOut(device,expression)        Output a real

 

IntIn and RlIn are similar to ChIn, but they input a number consisting of one or more digits instead of just a single character. If a series of numbers are typed on the keyboard and separated by spaces then each time IntIn(0) is called, it returns with the value of the next number. Any non-numeric character (or series of characters) are used to separate the numbers, such as space, comma, or a carriage return and line feed. If the numbers come from device 3, we have a numeric data file.

 

Integers and reals are normally represented outside a program as strings of ASCII characters. For example, IntOut(0,35) converts the integer 35 from its 16-bit binary form into an ASCII "3" character followed by an ASCII "5". Conversely, when numbers are input, strings of ASCII characters are converted into binary form.

 

Unlike some other languages, XPL0 has simple output commands. The advantage is that output can be formatted in a straightforward way. For example, when an integer is output, only the digits of the integer (and possibly a minus sign) are sent out. There are no "helpful" spaces or carriage returns sent that might not be wanted in some cases, and that might be confusing to eliminate. In XPL0 if you want formatting, you do it yourself.

 

Intrinsics used for I/O specify a device number. The device numbers for EXPL are slightly different from those used in previous versions. Click here for detailed information on device numbers.

 

Device 0
Device 1
Device 2
Device 3
Device 4
Device 5
Device 6
Device 7
Device 8
Device 9
Device 10