STANDARD PROCEDURE READ

Back to:
index

This procedure's call allows us to input value to the variables of different types directly from keyboard. This action would be done after program's compilation when you run the result executable code.

It is evident from above that this construction is in some parts similar to assign operator: both of them save the result of some operation into variable.

The execution of READ construction consists from 2 steps:
get value from keyboard to fixed register (R1 for "E97" and AX for Intel)
save the result of previous actions.

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

"COMPAS" compiles READ construction to a call of standard input 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.

    for INTEGER:
  • READLN(i);
    for CHAR:
  • READ(c);



Back to:
index top E97 Intel

"E97" code bricks

Here is a short pieces of "E97" code for input values of variables, which "COMPAS" inserts as a first part of READ construction (the second part - store this value to memory):

for INTEGER typefor CHAR type
9C0D
4108
call ROM subroutine 4108 9C0D
40FA
call ROM subroutine 40FA
0101R0 ==> R1
Note, that for CHAR type input subroutine returns result in R0, but "COMPAS" need it to be in R1.



Back to:
index top Intel

Example of full operator in "E97" code

READLN(x); (here DE is variable x address)

CodeOperationPascal comments
9C0D
4108
call 4108
(result - in R1)
Get number from keyboard
011E
00DE
R1 ==> (DE) Save this value to variable x



Back to:
index top

Intel code bricks

Here is a short pieces of Intel code for input values of variables, which "COMPAS" inserts as a first part of READ construction (the second part - store this value to memory):

for INTEGER typefor CHAR type
call 1E6call subroutine from RTL call 1CBcall subroutine from RTL



Back to:
index top E97

Example of full operator in Intel code

READLN(x); (here 4FE is variable x address)

CodeOperationPascal comments
E8 ?? ??call 1E6
(result - in AX)
Get number from keyboard
A3 FE 04mov [4FE],ax Save this value to variable x
Note that the content of displacement in call instruction (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