TAL Programmer's Guide

Binary-to-ASCII Conversion Program
Sample Programs
096254 Tandem Computers Incorporated A–5
Binary-to-ASCII
Conversion Program
This binary-to-ASCII conversion program performs a conversion function typical of
many algorithms in TAL. The program converts a binary INT value to an ASCII (base
10) value with a maximum length of six characters including the sign, then returns the
converted character string and its length to the calling procedure.
Significant items in Example A-5 are keyed to the following discussion:
Item Discussion
!1! Comments preceding the procedure declaration describe the purpose of the
procedure. For complex procedures, you can also summarize the input-output
characteristics and the main features of the algorithm.
!2! The formal parameter specifications define the parameters of the procedure.
Input parameters V and RJUST are value parameters, and output parameter
STG is a reference parameter.
!3! This local declaration reserves six bytes of memory for the buffer in which the
number is converted. The declaration also initializes the first five bytes in the
buffer to blanks (using a repetition factor of 5) and sets the last byte to an
ASCII 0. Thus, an input of 0 results in an output of five blanks and a 0, rather
than six blank characters.
!4! This IF statement deals with a negative INT binary number. When it
encounters a negative number, it sets the negative value flag to 1 and takes the
absolute value of the number passed.
!5! This WHILE loop performs the conversion, character by character, writing each
byte to the buffer from right to left.
!6! This assignment statement converts the binary INT value to an ASCII (base 10)
value. It illustrates an arithmetic expression that uses the standard procedure
$UDBL. The statement performs a residue modulo 10 operation, then adds an
ASCII 0 to the value of each byte to fit in the numeric range.
!7! This IF statement uses the assignment form of an arithmetic expression as the
condition.
!8! This IF statement moves the resulting character string from the buffer into the
user’s target string.
!9! The RETURN statement returns to the calling procedure the number of
characters moved.