STANDARD PROCEDURE WRITE

Back to:
index

This procedure's call allows us to output value of the variables of different types (INTEGER, CHAR, BOOLEAN) to display screen.

It is evident that this construction is in some parts similar to assign operator: both of them load the value of necessary variable.

The execution of WRITE construction consists from 2 steps:
get value of the variable to fixed register (R1 for "E97" and AX for Intel)
print this value using ROM subroutines.

Here we'll consider mainly the second part, because the first was under discussion in assignment.

"COMPAS" compiles WRITE construction to a call of standard output subroutine. In "E97" these subroutines are placed into ROM, and for Intel code - into Run-Time Library (RTL), which automatically adds to every executable program code.

Operator's structure

"E97" code bricks

Example of full operator in "E97" code

Intel code bricks

Example of full operator in Intel code


I called bricks the short pieces of code, that "COMPAS" generate as a part of operator. Compiler builds result machine code from the bricks.

Operator's structure

Examples of typical available in "COMPAS" constructions are exemplified below (they are identical for all types of variables):
  • WRITE(i);
  • WRITE(a[i]);
  • WRITELN(i);
  • WRITELN(a[i]);


  • Back to:
    index top E97 Intel

    "E97" code bricks

    Here is a short pieces of "E97" code for output values of variables, which "COMPAS" inserts as the second part of WRITE construction (the first part - read this value from memory):

    for INTEGER typefor CHAR typefor BOOLEAN type
    01D3
    00E0
    set buffer address to R3
    9C0D
    4068
    call ROM subroutine 4068 9C0D
    40BA
    call ROM subroutine 40BA 9C0D
    40C4
    call ROM subroutine 40C4
    Note that for INTEGER type output is the most complex procedure. So "COMPAS" has to reserve the 6-byte buffer for converting integer binary value to string. A special memory region 00E0 - 00E5 is used for these purposes.



    Back to:
    index top Intel

    Example of full operator in "E97" code

    WRITELN(c); (here DE is CHAR variable c address)

    CodeOperationPascal comments
    81E1
    00DE
    (DE)b ==> R1 Get byte value of variable c
    9C0D
    40BA
    call 40BA Print CHAR value from R1
    9C0D
    40EC
    call 40EC To next display line



    Back to:
    index top

    Intel code bricks

    Here is a short pieces of Intel code for output values of variables to display, which "COMPAS" inserts as a part of WRITE construction (the first part of the operator - get value from memory is not shown here):

    for INTEGER typefor CHAR typefor BOOLEAN type
    call 157call subroutine
    from RTL
    call 186call subroutine
    from RTL
    call 1B4call subroutine
    from RTL
    You can note the difference only in subroutine address.



    Back to:
    index top E97

    Example of full operator in Intel code

    WRITELN(i); (here 4FE is INTEGER variable i address)

    CodeOperationPascal comments
    A1 FE 04mov ax,[4FE] Put variable i value into AX
    E8 ?? ??call 157 Print AX value
    E8 ?? ??call 191 To next display line
    Note that the content of displacement in both call instructions (see the first column) depends from code position in memory (the address of RTL subroutine is always constant in "COMPAS"). So I wrote ?? ?? instead of concrete hex-digits in these positions.



    Back to:
    index top