This chapter describes the use of libraries in developing programs, as well as the details of the LIB291 library used in ECE 291.
A number of useful routines reside in the LIB291 library file. You are encouraged to use these routines whenever convenient to save programming time. At the end of this section is a detailed explanation of each routine. Following that, the code for two of the routines (binasc and ascbin) has been included to show you how they work.
Read in one ASCII character from the keyboard.
Read in one ASCII character from the keyboard and echo it to the screen.
Type out on the display screen one ASCII character.
Type out on the display screen a byte string of ASCII characters.
Exit from your program back to DOS.
Convert an ASCII string to an equivalent binary integer.
Convert a binary integer to an equivalent ASCII string.
Note: For some of the Machine Problems, special library files will be provided. These will contain major parts of the Machine Problems which you can use to help develop your code. If you need to use these libraries in order to demonstrate a working program you may; however, there will be penalties for doing so.
Note Carefully: LIB291 is written with the assumption of a single code/data segment which is GLOBAL and named CSEG. The subroutines also assume that registers DS, SS, and SP have been properly set up before they are called. It is the user's responsibility to set up the code/data segment as CSEG and to properly establish DS at CSEG and to have a usable stack segment pointed to by SS and SP upon entry.
To use the subroutines available in the library file, LIB291, you must do two things:
Declare the library subroutine(s) you wish to use as EXTERN in your own program:
EXTERN dosxit
Include the file name LIB291 in your TLINK command:
The TLINK program will then search through the file LIB291.LIB and bring in the appropriate subroutines called for by your program.
This routine awaits a single character typed in from the keyboard. The ASCII code for that character is returned in register AL. Note: kbdin does not echo the character back to the display screen.
Exits with:
AL = the ASCII code of the character typed in.
This subroutine is the same as kbdin except that in addition it echoes the received character onto the display screen before returning to the calling program.
Exits with:
AL = the ASCII code of the character typed in.
This routine types out on the display screen the ASCII-coded character in DL. A typewriter-like format is followed, i.e., successive characters are typed along a line until the end.
Call with:
DL = ASCII code of character to be typed on the display.
This routine prints a string of ASCII-coded characters on the display screen. The string must be terminated by an ASCII dollar sign ("$"). The starting offset of the string is to be given as an input in DX.
Call with:
DX = Offset address of first byte of the ASCII string to be typed.
This routine should be called as the last executed statement to clean up and return control to the DOS system, e.g.,
dosxit has no arguments.
This routine scans a string of characters (ASCII-coded digits) in successive bytes of memory, and generates a 16 bit binary integer which is the value of that string.
Call with:
BX = Offset address of first character of the ASCII string.
Exits with:
AX = Signed 16-bit integer having value of the ASCII string.
BX = Offset address of the first non-convertible character in the string (e.g., any ASCII character not a decimal digit).
DL = Status byte giving result of the conversion:
0 if no conversion errors
1 if string had no valid digits
2 if string had too many digits
3 if overflow
4 if underflow (value too negative)
This routine converts a 16 bit binary integer into a string of decimal characters (ASCII-coded digits), writing them as a byte string into memory. Following conversion, the character string may be moved from memory to the display.
Call with:
AX = The 16-bit, signed integer to be converted.
BX = Starting offset address for a 7-byte buffer to hold the byte string generated.
Exits with:
BX = The offset address of the first non-blank character of the string (this may be a minus sign, if the input number was negative). The string will be right-justified within the 7-byte buffer (padded with blanks to the left), and will have a "$" delimiter character after the last digit.
CL = Number of non-blank characters generated in the string (including the sign if given). Hence, CL = 3 for the number -78, and CL = 2 for the number 78.