The LIB306 Library of Subroutines

A number of useful routines reside in the LIB306 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.

kbdin

Read in one ASCII character from the keyboard.

kbdine

Read in one ASCII character from the keyboard and echo it to the screen.

dspout

Type out on the display screen one ASCII character.

dspmsg

Type out on the display screen a byte string of ASCII characters.

dosxit

Exit from your program back to DOS.

ascbin

Convert an ASCII string to an equivalent binary integer.

binasc

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.

Segment Assumptions

Note Carefully: LIB306 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.

LIB306 Subroutine Descriptions

kbdin

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.

kbdine

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.

dspout

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.

dspmsg

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.

Example: Use of dspmsg to type out the string tstmsg on the display

tstmsg  db      'TEST_MSG$'     ; (byte string in data
                                ; segment)
         |
        mov  dx, tstmsg
        call dspmsg             ; type it out
         |

dosxit

This routine should be called as the last executed statement to clean up and return control to the DOS system, e.g.,

         |
done:   call dosxit

dosxit has no arguments.

ascbin

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)

binasc

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.