Start of TRIGOL Compiler for a Program P6.tri at Sat Apr 03 16:11:44 2004


Program

# READ n
F:=1
I:=0
M1: I:=(I+1)
IF (I>n) THEN GOTO M2
F:=(F*I)
GOTO M1
M2: WRITE F#

Parsing tree

root
READ
n
:=
F1
:=
I0
label
M1
:=
I+
I1
IF
>
In
GOTO
label
M2
:=
F*
FI
GOTO
label
M1
label
M2
WRITE
F

Table of constants
c1=1c2=0

Table of identifiers
i1=ni2=Fi3=Ii4=M1i5=M2
label 'M1' is address of the operator {omistamine} (00481B00)
label 'M2' is address of the operator {kirjutamine} (00481920)

Modified tree:

root
READ
n
:=
F1
:=
I0
:=
I+
I1
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F


Compiler to Assembler started

; gen_header: source text
; # READ n ; F := 1 ; I := 0 ;
; M1 : I := I + 1 ;
; IF I > n THEN GOTO M2 ;
; F := F * I ;
; GOTO M1 ;
; M2 : WRITE F #
;
; Program P6.asm
	.MODEL	small
	.STACK	100h
; gen_header: Rd=1 Wr=1
EXTRN readint:PROC EXTRN bin2dec:PROC ; gen_header: # of identifiers=3
.DATA n DW 0 F DW 0 I DW 0 dTv0 DW 0 ; gen_header: generate I/O-text
Sisse DB 'Input the variable ','$' Trykk DB 'Variable ','$' n_S DB 'n=','$' F_S DB 'F=','$' ; gen_header: code segment'll start
.CODE ProgramStart: mov ax,@data mov ds,ax
Stackn
;compiling the operator READ n
READ
n
:=
F1
:=
I0
:=
I+
I1
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F
mov ah,9h mov bx,1 mov cx,17 mov dx,OFFSET Sisse int 21h mov ah,9h mov bx,1 mov cx,2 mov dx,OFFSET n_S int 21h call readint mov n,ax
Stack

StackF

StackF1
;compiling the operator F:=1
:=
F1
:=
I0
:=
I+
I1
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F
mov ax,1 mov F,ax
Stack

StackI

StackI0
;compiling the operator I:=0
:=
I0
:=
I+
I1
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F
mov ax,0 mov I,ax
Stack

StackI

StackII

StackII1
;compiling the operator (I+1)
+
I1
M1: mov ax,I add ax,1 mov dTv0,ax ;compiling the operator I:=(I+1)
:=
I+
I1
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F
mov ax,dTv0 mov I,ax
Stack

StackI

StackIn
;compiling the operator (I>n)
>
In
mov ax,I cmp ax,n jg M2 ;compiling the operator IF (I>n) THEN
IF
>
In
:=
F*
FI
GOTO
label
M1
WRITE
F

Stack

StackF

StackFF

StackFFI
;compiling the operator (F*I)
*
FI
mov ax,F mov dx,I mul dx mov dTv0,ax ;compiling the operator F:=(F*I)
:=
F*
FI
GOTO
label
M1
WRITE
F
mov ax,dTv0 mov F,ax
Stack

StackM1:
;compiling the operator M1:
label
M1

StackM1:
;compiling the operator GOTO M1
GOTO
label
M1
WRITE
F
jmp M1
Stack

StackF
;compiling the operator WRITE F
WRITE
F
M2: mov ah,9h mov bx,1 mov cx,8 mov dx,OFFSET Trykk int 21h mov ah,9h mov bx,1 mov cx,2 mov dx,OFFSET F_S int 21h mov ax,F mov dx,0 cmp ax,0 jg s1h2o3w mov dx,1 s1h2o3w: mov ch,1 call bin2dec
Stack
mov ah,4ch int 21h END ProgramStart programm P6.asm is compiled

I'll start compiler from assembler, and linker

tasm P6 >>P6c.htm
Turbo Assembler Version 3.1 Copyright (c) 1988, 1992 Borland International Assembling file: P6.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 457k
tlink P6+teek >>P6c.htm
Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International

Compiler ended at Sat Apr 03 16:11:46 2004